Skip to content

Commit

Permalink
fix extension type name
Browse files Browse the repository at this point in the history
  • Loading branch information
phyrog committed Sep 25, 2024
1 parent 1c992be commit 8167abb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
16 changes: 13 additions & 3 deletions cmd/gardener-extension-shoot-kubecost/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (

extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/util"
"github.com/gardener/gardener/pkg/logger"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle"

"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/component-base/version/verflag"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

Expand Down Expand Up @@ -47,6 +49,13 @@ func NewServiceControllerCommand() *cobra.Command {
}

func (o *Options) run(ctx context.Context) error {

log, err := logger.NewZapLogger(logger.InfoLevel, logger.FormatJSON)
if err != nil {
return fmt.Errorf("error instantiating zap logger: %w", err)
}
logf.SetLogger(log)

// TODO: Make these flags configurable via command line parameters or component config file.
util.ApplyClientConnectionConfigurationToRESTConfig(&componentbaseconfig.ClientConnectionConfiguration{
QPS: 100.0,
Expand All @@ -58,9 +67,10 @@ func (o *Options) run(ctx context.Context) error {
// do not enable a metrics server for the quick start
mgrOpts.Metrics.BindAddress = "0"

mgrOpts.Client.Cache = &client.CacheOptions{}
mgrOpts.Client.Cache.DisableFor = []client.Object{
&corev1.Secret{}, // applied for ManagedResources
mgrOpts.Client.Cache = &client.CacheOptions{
DisableFor: []client.Object{
&corev1.Secret{}, // applied for ManagedResources
},
}

mgr, err := manager.New(o.restOptions.Completed().Config, mgrOpts)
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package constants

const (
// ExtensionType is the name of the extension type.
ExtensionType = "shoot-flux"
ExtensionType = "shoot-kubecost"
// ServiceName is the name of the service.
ServiceName = ExtensionType

Expand Down
31 changes: 11 additions & 20 deletions pkg/controller/lifecycle/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// NewActuator returns an actuator responsible for Extension resources.
func NewActuator() extension.Actuator {
func NewActuator(client client.Client) extension.Actuator {
clientGardenlet := client
clientInterface, err := gardenclient.NewClientFromSecret(context.Background(), client, "garden", "gardenlet-kubeconfig")
if err == nil {
clientInterface.Start(context.Background())
clientGardenlet = clientInterface.Client()
}
return &actuator{
logger: log.Log.WithName("FirstLogger"),
client: client,
clientGardenlet: clientGardenlet,
logger: log.Log.WithName("FirstLogger"),
}
}

Expand All @@ -43,14 +50,14 @@ type actuator struct {

// Reconcile the Extension resource.
func (a *actuator) Reconcile(ctx context.Context, logger logr.Logger, ex *extensionsv1alpha1.Extension) error {
a.logger.Info("got resource to reconcile", "extension", *ex)
// get the shoot and the project namespace
extensionNamespace := ex.GetNamespace()
shoot, err := extensions.GetShoot(ctx, a.client, extensionNamespace)
if err != nil {
return err
}
projectNamespace := shoot.GetNamespace()
a.logger.Info("reconciling", "extension ns", extensionNamespace, "project ns", projectNamespace)

// fetch the secret holding the per-project configuration for the shoot-kubecost installation
kubeCostSecret := corev1.Secret{}
Expand Down Expand Up @@ -111,19 +118,3 @@ func getKubeCostApiKey(secretData map[string][]byte) (string, error) {
func createShootResourceKubeCostInstall(apiKey string) (map[string][]byte, error) {
return nil, nil
}

func (a *actuator) InjectClient(client client.Client) error {
a.client = client
clientInterface, err := gardenclient.NewClientFromSecret(context.Background(), a.client, "garden", "gardenlet-kubeconfig")
if err != nil {
return err
}
clientInterface.Start(context.Background())
a.clientGardenlet = clientInterface.Client()
return nil
}

func (a *actuator) InjectScheme(scheme *runtime.Scheme) error {
a.decoder = serializer.NewCodecFactory(scheme, serializer.EnableStrict).UniversalDecoder()
return nil
}
5 changes: 2 additions & 3 deletions pkg/controller/lifecycle/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ type AddOptions struct {
// AddToManager adds a shoot-kubecost Lifecycle controller to the given Controller Manager.
func AddToManager(ctx context.Context, mgr manager.Manager) error {
return extension.Add(ctx, mgr, extension.AddArgs{
Actuator: NewActuator(),
Actuator: NewActuator(mgr.GetClient()),
ControllerOptions: DefaultAddOptions.ControllerOptions,
Name: "shoot_kubecost_lifecycle_controller",
FinalizerSuffix: constants.ExtensionType,
Resync: 60 * time.Minute,
Predicates: extension.DefaultPredicates(ctx, mgr, DefaultAddOptions.IgnoreOperationAnnotation),
Resync: 1 * time.Minute,
Type: constants.ExtensionType,
})
}

0 comments on commit 8167abb

Please sign in to comment.