Skip to content

Commit ec5fa3d

Browse files
committed
Add support for marking a GitOpsCluster as provisioned.
If the GitOpsCluster is not a CAPI cluster, but has an annotation: metadata: annotations: clusters.gitops.weave.works/provisioned: "true" This will mark the GitOpsCluster as provisioned.
1 parent eed1f37 commit ec5fa3d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

controllers/gitopscluster_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/fluxcd/pkg/runtime/conditions"
2727
corev1 "k8s.io/api/core/v1"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/apimachinery/pkg/types"
3132
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -43,6 +44,10 @@ import (
4344
// finalize a GitOps cluster.
4445
const GitOpsClusterFinalizer = "clusters.gitops.weave.works"
4546

47+
// GitOpsClusterProvisionedAnnotation if applied to a GitOpsCluster indicates
48+
// that it should have a ready Provisioned condition.
49+
const GitOpsClusterProvisionedAnnotation = "clusters.gitops.weave.works/provisioned"
50+
4651
const (
4752
// SecretNameIndexKey is the key used for indexing secret
4853
// resources based on their name.
@@ -145,6 +150,11 @@ func (r *GitopsClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
145150
Namespace: cluster.GetNamespace(),
146151
Name: cluster.Spec.SecretRef.Name,
147152
}
153+
154+
if metav1.HasAnnotation(cluster.ObjectMeta, GitOpsClusterProvisionedAnnotation) {
155+
conditions.MarkTrue(cluster, gitopsv1alpha1.ClusterProvisionedCondition, gitopsv1alpha1.ClusterProvisionedReason, "Cluster Provisioned annotation detected")
156+
}
157+
148158
var secret corev1.Secret
149159
if err := r.Get(ctx, name, &secret); err != nil {
150160
e := fmt.Errorf("failed to get secret %q: %w", name, err)

controllers/gitopscluster_controller_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ func TestReconcile(t *testing.T) {
7979
wantCondition: meta.ReadyCondition,
8080
wantStatus: "True",
8181
},
82+
{
83+
name: "non-CAPI cluster has provisioned annotation",
84+
state: []runtime.Object{
85+
makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) {
86+
c.ObjectMeta.Annotations = map[string]string{
87+
controllers.GitOpsClusterProvisionedAnnotation: "true",
88+
}
89+
c.Spec.SecretRef = &meta.LocalObjectReference{
90+
Name: "dev",
91+
}
92+
}),
93+
},
94+
obj: types.NamespacedName{Namespace: testNamespace, Name: testName},
95+
// The referenced secret doesn't exist so we should still check for
96+
// it.
97+
requeueAfter: controllers.MissingSecretRequeueTime,
98+
wantCondition: gitopsv1alpha1.ClusterProvisionedCondition,
99+
wantStatus: "True",
100+
wantStatusMessage: "Cluster Provisioned annotation detected",
101+
},
82102
{
83103
name: "CAPI cluster does not exist",
84104
state: []runtime.Object{

0 commit comments

Comments
 (0)