Skip to content

Commit

Permalink
inject schema into actuator config
Browse files Browse the repository at this point in the history
  • Loading branch information
phyrog committed Sep 24, 2024
1 parent 0ec1859 commit 1c992be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/gardener-extension-shoot-kubecost/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package app
import (
"os"

"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle"
controllercmd "github.com/gardener/gardener/extensions/pkg/controller/cmd"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle"
)

// ExtensionName is the name of the extension.
Expand Down Expand Up @@ -52,7 +52,7 @@ func NewOptions() *Options {
},
reconcileOptions: &controllercmd.ReconcilerOptions{},
controllerSwitches: controllercmd.NewSwitchOptions(
controllercmd.Switch("shoot-kubecost_lifecycle_controller", lifecycle.AddToManager)),
controllercmd.Switch("shoot_kubecost_lifecycle_controller", lifecycle.AddToManager)),
}

options.optionAggregator = controllercmd.NewOptionAggregator(
Expand Down
18 changes: 14 additions & 4 deletions pkg/controller/lifecycle/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import (
_ "embed"
"errors"

"github.com/go-logr/logr"

"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants"

"github.com/gardener/gardener/extensions/pkg/controller/extension"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
gardenclient "github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/gardener/gardener/pkg/extensions"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants"

managedresources "github.com/gardener/gardener/pkg/utils/managedresources"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"

"github.com/go-logr/logr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand All @@ -35,10 +38,12 @@ type actuator struct {
logger logr.Logger // logger
client client.Client // seed cluster
clientGardenlet client.Client // garden cluster
decoder runtime.Decoder
}

// 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)
Expand Down Expand Up @@ -117,3 +122,8 @@ func (a *actuator) InjectClient(client client.Client) error {
a.clientGardenlet = clientInterface.Client()
return nil
}

func (a *actuator) InjectScheme(scheme *runtime.Scheme) error {
a.decoder = serializer.NewCodecFactory(scheme, serializer.EnableStrict).UniversalDecoder()
return nil
}
7 changes: 4 additions & 3 deletions pkg/controller/lifecycle/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/gardener/gardener/extensions/pkg/controller/extension"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/constants"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand All @@ -29,10 +30,10 @@ func AddToManager(ctx context.Context, mgr manager.Manager) error {
return extension.Add(ctx, mgr, extension.AddArgs{
Actuator: NewActuator(),
ControllerOptions: DefaultAddOptions.ControllerOptions,
Name: "shoot-kubecost_lifecycle_controller",
FinalizerSuffix: "shoot-kubecost",
Name: "shoot_kubecost_lifecycle_controller",
FinalizerSuffix: constants.ExtensionType,
Resync: 60 * time.Minute,
Predicates: extension.DefaultPredicates(ctx, mgr, DefaultAddOptions.IgnoreOperationAnnotation),
Type: "shoot-kubecost",
Type: constants.ExtensionType,
})
}

0 comments on commit 1c992be

Please sign in to comment.