Initial v1.0.0 commit

This commit is contained in:
Jakub Vavřík
2021-01-28 17:37:47 +01:00
commit 1481d27782
4164 changed files with 1264675 additions and 0 deletions
@@ -0,0 +1,95 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
"context"
"fmt"
"github.com/javamachr/gardener-extension-shoot-fleet-agent/pkg/controller"
"github.com/javamachr/gardener-extension-shoot-fleet-agent/pkg/controller/healthcheck"
extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/util"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
componentbaseconfig "k8s.io/component-base/config"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
// NewServiceControllerCommand creates a new command that is used to start the Fleet Service controller.
func NewServiceControllerCommand() *cobra.Command {
options := NewOptions()
cmd := &cobra.Command{
Use: "shoot-fleet-agent-controller-manager",
Short: "Shoot Fleet Service Controller manages components which register Cluster in Fleet.",
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.optionAggregator.Complete(); err != nil {
return fmt.Errorf("error completing options: %s", err)
}
cmd.SilenceUsage = true
return options.run(cmd.Context())
},
}
options.optionAggregator.AddFlags(cmd.Flags())
return cmd
}
func (o *Options) run(ctx context.Context) error {
// TODO: Make these flags configurable via command line parameters or component config file.
util.ApplyClientConnectionConfigurationToRESTConfig(&componentbaseconfig.ClientConnectionConfiguration{
QPS: 100.0,
Burst: 130,
}, o.restOptions.Completed().Config)
mgrOpts := o.managerOptions.Completed().Options()
mgrOpts.ClientDisableCacheFor = []client.Object{
&corev1.Secret{}, // applied for ManagedResources
&corev1.ConfigMap{}, // applied for monitoring config
}
mgr, err := manager.New(o.restOptions.Completed().Config, mgrOpts)
if err != nil {
return fmt.Errorf("could not instantiate controller-manager: %s", err)
}
if err := extensionscontroller.AddToScheme(mgr.GetScheme()); err != nil {
return fmt.Errorf("could not update manager scheme: %s", err)
}
ctrlConfig := o.fleetOptions.Completed()
ctrlConfig.Apply(&controller.DefaultAddOptions.ServiceConfig)
o.controllerOptions.Completed().Apply(&controller.DefaultAddOptions.ControllerOptions)
o.healthOptions.Completed().Apply(&healthcheck.DefaultAddOptions.Controller)
o.reconcileOptions.Completed().Apply(&controller.DefaultAddOptions.IgnoreOperationAnnotation)
if err := o.controllerSwitches.Completed().AddToManager(mgr); err != nil {
return fmt.Errorf("could not add controllers to manager: %s", err)
}
if err := mgr.Start(ctx); err != nil {
return fmt.Errorf("error running manager: %s", err)
}
return nil
}
@@ -0,0 +1,74 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package app
import (
"os"
fleetagentservicecmd "github.com/javamachr/gardener-extension-shoot-fleet-agent/pkg/cmd"
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
)
// ExtensionName is the name of the extension.
const ExtensionName = "extension-shoot-fleet-agent"
// Options holds configuration passed to the Fleet Service controller.
type Options struct {
fleetOptions *fleetagentservicecmd.FleetServiceOptions
restOptions *controllercmd.RESTOptions
managerOptions *controllercmd.ManagerOptions
controllerOptions *controllercmd.ControllerOptions
healthOptions *controllercmd.ControllerOptions
controllerSwitches *controllercmd.SwitchOptions
reconcileOptions *controllercmd.ReconcilerOptions
optionAggregator controllercmd.OptionAggregator
}
// NewOptions creates a new Options instance.
func NewOptions() *Options {
options := &Options{
fleetOptions: &fleetagentservicecmd.FleetServiceOptions{},
restOptions: &controllercmd.RESTOptions{},
managerOptions: &controllercmd.ManagerOptions{
// These are default values.
LeaderElection: true,
LeaderElectionID: controllercmd.LeaderElectionNameID(ExtensionName),
LeaderElectionNamespace: os.Getenv("LEADER_ELECTION_NAMESPACE"),
},
controllerOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
healthOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
controllerSwitches: fleetagentservicecmd.ControllerSwitches(),
reconcileOptions: &controllercmd.ReconcilerOptions{},
}
options.optionAggregator = controllercmd.NewOptionAggregator(
options.restOptions,
options.managerOptions,
options.controllerOptions,
options.fleetOptions,
controllercmd.PrefixOption("healthcheck-", options.healthOptions),
options.controllerSwitches,
options.reconcileOptions,
)
return options
}
@@ -0,0 +1,33 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"github.com/javamachr/gardener-extension-shoot-fleet-agent/cmd/gardener-extension-shoot-fleet-agent/app"
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
"github.com/gardener/gardener/extensions/pkg/log"
runtimelog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)
func main() {
runtimelog.SetLogger(log.ZapLogger(false))
ctx := signals.SetupSignalHandler()
if err := app.NewServiceControllerCommand().ExecuteContext(ctx); err != nil {
controllercmd.LogErrAndExit(err, "error executing the main controller command")
}
}