Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,21 @@ linters:
replace-allow-list:
# for go-pmtud
- github.com/mdlayher/arp
# for github.com/sapcc/vpa_butler
- k8s.io/client-go
# synced from greenhouse v0.9.0
# synced from greenhouse v0.11.1
- github.com/fluxcd/helm-controller/api
- github.com/fluxcd/kustomize-controller/api
- github.com/fluxcd/pkg/apis/kustomize
- github.com/fluxcd/pkg/apis/meta
- github.com/fluxcd/source-controller/api
- github.com/fluxcd/source-watcher/api/v2
- k8s.io/api
- k8s.io/apiextensions-apiserver
- k8s.io/apimachinery
- k8s.io/cli-runtime
- k8s.io/client-go
- k8s.io/component-base
- k8s.io/kubectl
- sigs.k8s.io/controller-runtime
toolchain-forbidden: true
go-version-pattern: 1\.\d+(\.0)?$
gosec:
Expand Down
2 changes: 1 addition & 1 deletion controller/careinstruction/careinstruction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (r *CareInstructionReconciler) reconcileManager(ctx context.Context, careIn
Logger: r.WithValues("careInstruction", careInstruction.Name),
Name: shoot.GenerateName(careInstruction.Name),
CareInstruction: careInstruction.DeepCopy(),
EventRecorder: r.GetEventRecorderFor(shoot.GenerateName(careInstruction.Name)),
EventRecorder: r.GetEventRecorder(shoot.GenerateName(careInstruction.Name)),
}
if err := sc.SetupWithManager(shootControllerMgr); err != nil {
return err
Expand Down
26 changes: 6 additions & 20 deletions controller/shoot/shoot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -40,13 +40,13 @@ type ShootController struct {
logr.Logger
Name string
CareInstruction *v1alpha1.CareInstruction
EventRecorder record.EventRecorder // EventRecorder to emit events on the Greenhouse cluster
EventRecorder events.EventRecorder // EventRecorder to emit events on the Greenhouse cluster
}

// emitEvent safely emits an event if EventRecorder is available
func (r *ShootController) emitEvent(object client.Object, eventType, reason, message string) {
if r.EventRecorder != nil {
r.EventRecorder.Event(object, eventType, reason, message)
r.EventRecorder.Eventf(object, nil, eventType, reason, reason, "%s", message)
} else {
r.Info("Event (EventRecorder not available)", "type", eventType, "reason", reason, "message", message)
}
Expand Down Expand Up @@ -148,33 +148,19 @@ func (r *ShootController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, nil
}

// Specify which labels to propagate from the Shoot to the Secret - LabelPropagator needs to have the labels set on the source object.
// TODO: change when LabelPropagator is extended to accommodate this scenario.
if shoot.Annotations == nil {
shoot.Annotations = make(map[string]string)
}
shoot.Annotations[lifecycle.PropagateLabelsAnnotation] = strings.Join(r.CareInstruction.Spec.PropagateLabels, ",")

// Specify which labels should be propagated from the Secret (by Greenhouse to create Cluster)
labelKeysToPropagate := r.CareInstruction.Spec.PropagateLabels

// Initialize secret labels based on CareInstruction
secretLabels := make(map[string]string)

// Get additional labels to set on the Secret
if r.CareInstruction.Spec.AdditionalLabels != nil {
for k, v := range r.CareInstruction.Spec.AdditionalLabels {
secretLabels[k] = v
labelKeysToPropagate = append(labelKeysToPropagate, k)
}
maps.Copy(secretLabels, r.CareInstruction.Spec.AdditionalLabels)
}

// Set the identifying label
secretLabels[v1alpha1.CareInstructionLabel] = r.CareInstruction.Name
labelKeysToPropagate = append(labelKeysToPropagate, v1alpha1.CareInstructionLabel)

secretAnnotations := map[string]string{
"greenhouse.sap/propagate-labels": strings.Join(labelKeysToPropagate, ","),
greenhouseapis.SecretAPIServerURLAnnotation: apiServerURL,
}
Comment thread
Zaggy21 marked this conversation as resolved.

Expand Down Expand Up @@ -227,8 +213,8 @@ func (r *ShootController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}
maps.Copy(secret.Labels, secretLabels)

// Transport Shoot labels to the Secret
secret = (lifecycle.NewPropagator(&shoot, secret).Apply()).(*corev1.Secret)
// Copy Shoot labels to the Secret
secret = (lifecycle.NewPropagator(&shoot, secret).CopyLabels(r.CareInstruction.Spec.PropagateLabels)).(*corev1.Secret)
return nil
})
if err != nil {
Expand Down
14 changes: 1 addition & 13 deletions controller/shoot/shoot_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var _ = Describe("Shoot Controller", func() {
Logger: ctrl.Log.WithName("controllers").WithName("ShootController"),
Name: "ShootController",
CareInstruction: careInstruction,
EventRecorder: greenhouseMgr.GetEventRecorderFor("ShootController"), // Get EventRecorder from Greenhouse manager
EventRecorder: greenhouseMgr.GetEventRecorder("ShootController"),
}).SetupWithManager(mgr)).To(Succeed(), "there must be no error setting up the controller with the manager")

careInstructionWebhook := &webhookv1alpha1.CareInstructionWebhook{}
Expand Down Expand Up @@ -313,8 +313,6 @@ var _ = Describe("Shoot Controller", func() {
"quux": "corge",
},
Annotations: map[string]string{
"greenhouse.sap/last-applied-propagator": "{\"labelKeys\":[\"foo\",\"baz\"]}",
"greenhouse.sap/propagate-labels": "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction",
greenhouseapis.SecretAPIServerURLAnnotation: "https://api-server.test-shoot-1.example.com",
},
},
Expand Down Expand Up @@ -394,8 +392,6 @@ var _ = Describe("Shoot Controller", func() {
"quux": "corge",
},
Annotations: map[string]string{
"greenhouse.sap/last-applied-propagator": "{\"labelKeys\":[\"foo\",\"baz\"]}",
"greenhouse.sap/propagate-labels": "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction",
greenhouseapis.SecretAPIServerURLAnnotation: "https://api-server.test-shoot-1.example.com",
},
},
Expand All @@ -414,8 +410,6 @@ var _ = Describe("Shoot Controller", func() {
"quux": "corge",
},
Annotations: map[string]string{
"greenhouse.sap/last-applied-propagator": "{\"labelKeys\":[\"foo\",\"baz\"]}",
"greenhouse.sap/propagate-labels": "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction",
greenhouseapis.SecretAPIServerURLAnnotation: "https://api-server.test-shoot-2.example.com",
},
},
Expand Down Expand Up @@ -494,8 +488,6 @@ var _ = Describe("Shoot Controller", func() {
"quux": "corge",
},
Annotations: map[string]string{
"greenhouse.sap/last-applied-propagator": "{\"labelKeys\":[\"foo\",\"baz\"]}",
"greenhouse.sap/propagate-labels": "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction",
greenhouseapis.SecretAPIServerURLAnnotation: "https://api-server.test-shoot-1.example.com",
},
},
Expand Down Expand Up @@ -585,7 +577,6 @@ var _ = Describe("Shoot Controller", func() {
g.Expect(err).NotTo(HaveOccurred(), "should get secret")

// Check that controller-managed annotations are present
g.Expect(secret.Annotations).To(HaveKeyWithValue("greenhouse.sap/propagate-labels", "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction"))
g.Expect(secret.Annotations).To(HaveKeyWithValue(greenhouseapis.SecretAPIServerURLAnnotation, "https://api-server.test-shoot-merge.example.com"))

// Check that external annotation is preserved
Expand Down Expand Up @@ -680,7 +671,6 @@ var _ = Describe("Shoot Controller", func() {
g.Expect(err).NotTo(HaveOccurred(), "should get secret")

// Check that controller-managed annotations are present
g.Expect(secret.Annotations).To(HaveKeyWithValue("greenhouse.sap/propagate-labels", "test/*,quux,shoot-grafter.cloudoperators.dev/careinstruction"))
g.Expect(secret.Annotations).To(HaveKeyWithValue(greenhouseapis.SecretAPIServerURLAnnotation, "https://api-server.test-shoot-merge.example.com"))

// Check that external annotation is preserved
Expand Down Expand Up @@ -776,8 +766,6 @@ var _ = Describe("Shoot Controller", func() {
"quux": "corge",
}), "should have the expected labels")
g.Expect(secret.Annotations).To(Equal(map[string]string{
"greenhouse.sap/last-applied-propagator": "{\"labelKeys\":[\"foo\",\"baz\"]}",
"greenhouse.sap/propagate-labels": "foo,baz,quux,shoot-grafter.cloudoperators.dev/careinstruction",
greenhouseapis.SecretAPIServerURLAnnotation: "https://api-server.test-shoot.example.com",
}), "should have the expected annotations")
g.Expect(secret.Data).To(HaveKeyWithValue("ca.crt", []byte(base64.StdEncoding.EncodeToString([]byte("test-ca-data")))), "should have the expected data")
Expand Down
84 changes: 47 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
module shoot-grafter

go 1.26
go 1.26.0

// Synced from greenhouse v0.9.0 go.mod
// Synced from greenhouse v0.11.1 go.mod
replace (
// Keep Flux dependencies in sync with v2.6.1.
github.com/fluxcd/helm-controller/api => github.com/fluxcd/helm-controller/api v1.4.5
github.com/fluxcd/kustomize-controller/api => github.com/fluxcd/kustomize-controller/api v1.7.3
github.com/fluxcd/pkg/apis/kustomize => github.com/fluxcd/pkg/apis/kustomize v1.14.0
github.com/fluxcd/pkg/apis/meta => github.com/fluxcd/pkg/apis/meta v1.23.0
github.com/fluxcd/pkg/apis/kustomize => github.com/fluxcd/pkg/apis/kustomize v1.15.1
github.com/fluxcd/pkg/apis/meta => github.com/fluxcd/pkg/apis/meta v1.25.1
github.com/fluxcd/source-controller/api => github.com/fluxcd/source-controller/api v1.7.4
github.com/fluxcd/source-watcher/api/v2 => github.com/fluxcd/source-watcher/api/v2 v2.0.3

// Keep k8s dependencies in sync.
k8s.io/api => k8s.io/api v0.35.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.35.0
k8s.io/apimachinery => k8s.io/apimachinery v0.35.1
k8s.io/cli-runtime => k8s.io/cli-runtime v0.35.0
k8s.io/client-go => k8s.io/client-go v0.35.0
k8s.io/component-base => k8s.io/component-base v0.35.0
k8s.io/kubectl => k8s.io/kubectl v0.35.0
Comment thread
Zaggy21 marked this conversation as resolved.
Outdated
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.23.1
)

require (
github.com/cloudoperators/greenhouse v0.9.0
github.com/cloudoperators/greenhouse v0.11.1
github.com/gardener/gardener v1.133.0
github.com/go-logr/logr v1.4.3
github.com/onsi/ginkgo/v2 v2.27.3
github.com/onsi/gomega v1.38.2
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.1
github.com/prometheus/client_golang v1.23.2
go.uber.org/zap v1.27.1
k8s.io/api v0.34.3
k8s.io/apimachinery v0.35.0
k8s.io/apiserver v0.34.3
k8s.io/client-go v0.34.3
k8s.io/kubectl v0.34.2
sigs.k8s.io/controller-runtime v0.22.4
k8s.io/api v0.35.1
k8s.io/apimachinery v0.35.2
k8s.io/apiserver v0.35.1
k8s.io/client-go v0.35.1
k8s.io/kubectl v0.35.1
sigs.k8s.io/controller-runtime v0.23.1
sigs.k8s.io/yaml v1.6.0
)

require (
cel.dev/expr v0.24.0 // indirect
cel.dev/expr v0.25.1 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -40,7 +51,7 @@ require (
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fluxcd/pkg/apis/acl v0.9.0 // indirect
github.com/fluxcd/pkg/apis/meta v1.23.0 // indirect
github.com/fluxcd/pkg/apis/meta v1.25.1 // indirect
github.com/fluxcd/source-controller/api v1.7.4 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
Expand All @@ -62,10 +73,10 @@ require (
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/cel-go v0.26.1 // indirect
github.com/google/cel-go v0.28.0 // 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-20250903194437-c28834ac2320 // indirect
github.com/google/pprof v0.0.0-20260115054156-294ebfa9ad83 // 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
Expand All @@ -79,36 +90,35 @@ require (
github.com/prometheus/common v0.67.4 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/term v0.42.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.40.0 // indirect
golang.org/x/tools v0.44.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
google.golang.org/protobuf v1.36.10 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 // indirect
google.golang.org/protobuf v1.36.11 // 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.34.3 // indirect
k8s.io/component-base v0.34.3 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/apiextensions-apiserver v0.35.2 // indirect
k8s.io/component-base v0.35.1 // indirect
k8s.io/klog/v2 v2.140.0 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
k8s.io/utils v0.0.0-20251222233032-718f0e51e6d2 // indirect
k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 // 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.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
)
Loading
Loading