Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/v1alpha1/careinstruction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package v1alpha1
import (
"context"
"fmt"
"slices"

greenhousemetav1alpha1 "github.com/cloudoperators/greenhouse/api/meta/v1alpha1"
greenhousev1alpha1 "github.com/cloudoperators/greenhouse/api/v1alpha1"
Expand Down Expand Up @@ -168,6 +169,22 @@ func init() {
})
}

func (c *CareInstruction) CanBeSuspended() bool { return false }

func (c *CareInstruction) GetConditions() greenhousemetav1alpha1.StatusConditions {
return c.Status.StatusConditions
}

func (c *CareInstruction) SetCondition(condition greenhousemetav1alpha1.Condition) {
c.Status.SetConditions(condition)
}

func (c *CareInstruction) RemoveCondition(conditionType greenhousemetav1alpha1.ConditionType) {
c.Status.Conditions = slices.DeleteFunc(c.Status.Conditions, func(cond greenhousemetav1alpha1.Condition) bool {
return cond.Type == conditionType
})
}

// ListShoots returns shoots matching the ShootSelector.LabelSelector.
func (c *CareInstruction) ListShoots(ctx context.Context, gardenClient client.Client) (gardenerv1beta1.ShootList, error) {
shootList := gardenerv1beta1.ShootList{}
Expand Down
105 changes: 45 additions & 60 deletions controller/careinstruction/careinstruction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
greenhouseapis "github.com/cloudoperators/greenhouse/api"
greenhousemetav1alpha1 "github.com/cloudoperators/greenhouse/api/meta/v1alpha1"
greenhousev1alpha1 "github.com/cloudoperators/greenhouse/api/v1alpha1"
"github.com/cloudoperators/greenhouse/pkg/lifecycle"
gardenerv1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -85,44 +86,28 @@ func (r *CareInstructionReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *CareInstructionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Logger = ctrl.LoggerFrom(ctx)
r.Info("Reconciling CareInstruction", "name", req.Name, "namespace", req.Namespace)
return lifecycle.Reconcile(ctx, r.Client, req.NamespacedName, &v1alpha1.CareInstruction{}, r, nil)
}

var careInstruction v1alpha1.CareInstruction
if err := r.Get(ctx, req.NamespacedName, &careInstruction); err != nil {
r.Error(err, "unable to fetch CareInstruction")
return ctrl.Result{}, client.IgnoreNotFound(err)
}
func (r *CareInstructionReconciler) GetFinalizerName() string {
return v1alpha1.CommonCleanupFinalizer
}

// initialize the context with the original CareInstruction object
ctx = context.WithValue(ctx, careInstructionContextKey{}, careInstruction.DeepCopyObject())
shouldBeDeleted := (careInstruction.GetDeletionTimestamp() != nil)
hasFinalizer := controllerutil.ContainsFinalizer(&careInstruction, v1alpha1.CommonCleanupFinalizer)
func (r *CareInstructionReconciler) EnsureCreated(ctx context.Context, obj lifecycle.RuntimeObject) (ctrl.Result, lifecycle.ReconcileResult, error) {
r.Logger = ctrl.LoggerFrom(ctx)
r.Info("Reconciling CareInstruction creation/updating", "name", obj.GetName(), "namespace", obj.GetNamespace())

// check whether finalizer is set
if !shouldBeDeleted && !hasFinalizer {
return ctrl.Result{}, r.ensureFinalizer(ctx, &careInstruction, v1alpha1.CommonCleanupFinalizer)
}
careInstruction := obj.(*v1alpha1.CareInstruction)

// Initialize conditions to unknown if not set
initializeConditionsToUnknown(&careInstruction)
initializeConditionsToUnknown(careInstruction)
defer func(careInstruction *v1alpha1.CareInstruction) {
if statusErr := r.reconcileStatus(ctx, careInstruction); statusErr != nil {
r.Error(statusErr, "failed to reconcile status")
}
}(&careInstruction)

// Deletion logic
if shouldBeDeleted {
// reconcile again for finalizer
if !hasFinalizer {
return ctrl.Result{}, nil
}
err := r.cleanupCareInstruction(ctx, &careInstruction)
return ctrl.Result{}, err
}
}(careInstruction)

if err := r.ensureAuthConfigMapLabeled(ctx, &careInstruction); err != nil {
if err := r.ensureAuthConfigMapLabeled(ctx, careInstruction); err != nil {
r.Error(err, "failed to ensure auth ConfigMap is labeled")
}

Expand All @@ -135,11 +120,12 @@ func (r *CareInstructionReconciler) Reconcile(ctx context.Context, req ctrl.Requ
err.Error(),
),
)
return ctrl.Result{}, err

return ctrl.Result{}, lifecycle.Failed, err
}

// reconcile Shoots and Clusters created by this CareInstruction
if err := r.reconcileShootsNClusters(ctx, &careInstruction); err != nil {
if err := r.reconcileShootsNClusters(ctx, careInstruction); err != nil {
r.Info("failed to reconcile shoots and clusters for CareInstruction, will retry", "error", err.Error())
careInstruction.Status.SetConditions(
greenhousemetav1alpha1.FalseCondition(
Expand All @@ -150,27 +136,36 @@ func (r *CareInstructionReconciler) Reconcile(ctx context.Context, req ctrl.Requ
)
}

return ctrl.Result{}, nil
return ctrl.Result{}, lifecycle.Success, nil
}

// ensureFinalizer - ensures a finalizer is present on the object. Returns an error on failure.
func (r *CareInstructionReconciler) ensureFinalizer(ctx context.Context, o client.Object, finalizer string) error {
if controllerutil.AddFinalizer(o, finalizer) {
return r.Update(ctx, o)
}
return nil
}
func (r *CareInstructionReconciler) EnsureDeleted(ctx context.Context, obj lifecycle.RuntimeObject) (ctrl.Result, lifecycle.ReconcileResult, error) {
r.Logger = ctrl.LoggerFrom(ctx)
r.Info("Reconciling CareInstruction removal", "name", obj.GetName(), "namespace", obj.GetNamespace())
careInstruction := obj.(*v1alpha1.CareInstruction)

// initialize the context with the original CareInstruction object
ctx = context.WithValue(ctx, careInstructionContextKey{}, careInstruction.DeepCopyObject())

// removeFinalizer - removes a finalizer from an object. Returns an error on failure.
func (r *CareInstructionReconciler) removeFinalizer(ctx context.Context, o client.Object, finalizer string) error {
if controllerutil.RemoveFinalizer(o, finalizer) {
return r.Update(ctx, o)
// Initialize conditions to unknown if not set
initializeConditionsToUnknown(careInstruction)
defer func(careInstruction *v1alpha1.CareInstruction) {
if statusErr := r.reconcileStatus(ctx, careInstruction); statusErr != nil {
r.Error(statusErr, "failed to reconcile status")
}
}(careInstruction)

hasFinalizer := controllerutil.ContainsFinalizer(careInstruction, v1alpha1.CommonCleanupFinalizer)
if !hasFinalizer {
return ctrl.Result{}, lifecycle.Success, nil
}
return nil

r.cleanupCareInstruction(careInstruction)
return ctrl.Result{}, lifecycle.Success, nil
}

// reconcileManager - reconciles the shoot controller manager for the given CareInstruction.
func (r *CareInstructionReconciler) reconcileManager(ctx context.Context, careInstruction v1alpha1.CareInstruction) error {
func (r *CareInstructionReconciler) reconcileManager(ctx context.Context, careInstruction *v1alpha1.CareInstruction) error {
r.Info("Reconciling shoot controller manager for garden cluster", "name", careInstruction.Spec.GardenClusterName)

// Use namespace-qualified key to prevent collisions between CareInstructions with the same name in different namespaces
Expand Down Expand Up @@ -212,7 +207,7 @@ func (r *CareInstructionReconciler) reconcileManager(ctx context.Context, careIn
}
r.gardensMu.Unlock()

gardenClientConfig, scheme, err := r.GetGardenClusterAccess(ctx, &careInstruction)
gardenClientConfig, scheme, err := r.GetGardenClusterAccess(ctx, careInstruction)
// Get Access to the Garden Cluster
if err != nil {
careInstruction.Status.SetConditions(
Expand Down Expand Up @@ -583,7 +578,7 @@ func (r *CareInstructionReconciler) restartShootController(careInstruction *v1al
}

// cleanupCareInstruction - deletes the CareInstruction and cleans up any resources associated with it.
func (r *CareInstructionReconciler) cleanupCareInstruction(ctx context.Context, careInstruction *v1alpha1.CareInstruction) error {
func (r *CareInstructionReconciler) cleanupCareInstruction(careInstruction *v1alpha1.CareInstruction) {
r.Info("Cleaning up CareInstruction", "name", careInstruction.Name, "namespace", careInstruction.Namespace)
careInstruction.Status.SetConditions(
greenhousemetav1alpha1.FalseCondition(
Expand All @@ -606,20 +601,6 @@ func (r *CareInstructionReconciler) cleanupCareInstruction(ctx context.Context,
r.gardensMu.Unlock()
r.Info("Garden manager context not found for careInstruction: " + careInstruction.Name)
}
// Remove the finalizer
if err := r.removeFinalizer(ctx, careInstruction, v1alpha1.CommonCleanupFinalizer); err != nil {
r.Error(err, "Unable to remove finalizer from CareInstruction", "name", careInstruction.Name)
careInstruction.Status.SetConditions(
greenhousemetav1alpha1.FalseCondition(
v1alpha1.DeleteCondition,
"FinalizerError",
err.Error(),
),
)
return err
}
r.Info("Removed finalizer from CareInstruction", "name", careInstruction.Name)
return nil
}

// ensureAuthConfigMapLabeled patches the auth ConfigMap with AuthConfigMapLabel if it is missing,
Expand Down Expand Up @@ -741,3 +722,7 @@ func (r *CareInstructionReconciler) enqueueCareInstructionForAuthConfigMap(ctx c
}
return requests
}

func (r *CareInstructionReconciler) EnsureSuspended(_ context.Context, _ lifecycle.RuntimeObject) (ctrl.Result, error) {
return ctrl.Result{}, nil
}
84 changes: 41 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ replace (
)

require (
github.com/cloudoperators/greenhouse v0.14.0
github.com/cloudoperators/greenhouse/api v0.14.0
github.com/cloudoperators/greenhouse v0.16.1-0.20260825173926-60ab962059ff
github.com/cloudoperators/greenhouse/api v0.16.1-0.20260825173926-60ab962059ff

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary change. Waiting for a new release of greenhouse.

github.com/gardener/gardener v1.133.0
github.com/go-logr/logr v1.4.3
github.com/onsi/ginkgo/v2 v2.29.0
github.com/onsi/gomega v1.41.0
github.com/prometheus/client_golang v1.23.2
github.com/go-logr/logr v1.4.4
github.com/onsi/ginkgo/v2 v2.32.1
github.com/onsi/gomega v1.42.1
github.com/prometheus/client_golang v1.24.1
go.uber.org/zap v1.28.0
k8s.io/api v0.36.0
k8s.io/apimachinery v0.36.0
k8s.io/apiserver v0.36.0
k8s.io/client-go v0.36.0
k8s.io/kubectl v0.36.0
k8s.io/api v0.36.2
k8s.io/apimachinery v0.36.2
k8s.io/apiserver v0.36.2
k8s.io/client-go v0.36.2
k8s.io/kubectl v0.36.2
sigs.k8s.io/controller-runtime v0.24.1
sigs.k8s.io/yaml v1.6.0
)

require (
cel.dev/cel-go v0.32.0 // indirect
cel.dev/expr v0.25.1 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/Masterminds/semver/v3 v3.5.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand All @@ -52,70 +53,67 @@ require (
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.22.1 // indirect
github.com/go-openapi/jsonreference v0.21.2 // indirect
github.com/go-openapi/swag v0.24.1 // indirect
github.com/go-openapi/swag/cmdutils v0.24.0 // indirect
github.com/go-openapi/swag/conv v0.24.0 // indirect
github.com/go-openapi/swag/fileutils v0.24.0 // indirect
github.com/go-openapi/swag/jsonname v0.25.1 // indirect
github.com/go-openapi/swag/jsonutils v0.24.0 // indirect
github.com/go-openapi/swag/loading v0.24.0 // indirect
github.com/go-openapi/swag/mangling v0.24.0 // indirect
github.com/go-openapi/swag/netutils v0.24.0 // indirect
github.com/go-openapi/swag/stringutils v0.24.0 // indirect
github.com/go-openapi/swag/typeutils v0.24.0 // indirect
github.com/go-openapi/swag/yamlutils v0.24.0 // indirect
github.com/go-openapi/swag v0.25.4 // indirect
github.com/go-openapi/swag/cmdutils v0.25.4 // indirect
github.com/go-openapi/swag/conv v0.25.4 // indirect
github.com/go-openapi/swag/fileutils v0.25.4 // indirect
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
github.com/go-openapi/swag/loading v0.25.4 // indirect
github.com/go-openapi/swag/mangling v0.25.4 // indirect
github.com/go-openapi/swag/netutils v0.25.4 // indirect
github.com/go-openapi/swag/stringutils v0.25.4 // indirect
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/cel-go v0.28.1 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.13-0.20220915233716-71ac16282d12 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
github.com/prometheus/common v0.70.1 // indirect
github.com/prometheus/procfs v0.21.1 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/mod v0.37.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/mod v0.38.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/term v0.44.0 // indirect
golang.org/x/text v0.38.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/term v0.45.0 // indirect
golang.org/x/text v0.40.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.46.0 // indirect
golang.org/x/tools v0.48.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260406210006-6f92a3bedf2d // indirect
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.36.0 // indirect
k8s.io/component-base v0.36.0 // indirect
k8s.io/apiextensions-apiserver v0.36.2 // indirect
k8s.io/component-base v0.36.2 // indirect
k8s.io/klog/v2 v2.140.0 // indirect
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 // indirect
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25 // indirect
k8s.io/utils v0.0.0-20260707023825-cf1189d6abe3 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.4.0 // indirect
)
Loading
Loading