Skip to content

Commit 5ecdca1

Browse files
committed
move general openmcp constants into own api package
1 parent 670d722 commit 5ecdca1

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

Taskfile.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ includes:
77
excludes: [] # put task names in here which are overwritten in this file
88
vars:
99
NESTED_MODULES: api
10-
API_DIRS: '{{.ROOT_DIR}}/api/provider/v1alpha1/... {{.ROOT_DIR}}/api/clusters/v1alpha1/...'
10+
API_DIRS: '{{.ROOT_DIR}}/api/...'
1111
MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests'
12-
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/provider/v1alpha1/... {{.ROOT_DIR}}/api/clusters/v1alpha1/...'
12+
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/...'
1313
COMPONENTS: 'openmcp-operator'
1414
REPO_URL: 'https://github.com/openmcp-project/openmcp-operator'
1515
GENERATE_DOCS_INDEX: "true"

api/clusters/v1alpha1/constants.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ const (
5656
)
5757

5858
const (
59-
// ClusterLabel can be used on CRDs to indicate onto which cluster they should be deployed.
60-
ClusterLabel = ParentGroupName + "/cluster"
61-
// OperationAnnotation is used to trigger specific operations on resources.
62-
OperationAnnotation = ParentGroupName + "/operation"
63-
// OperationAnnotationValueIgnore is used to ignore the resource.
64-
OperationAnnotationValueIgnore = "ignore"
65-
// OperationAnnotationValueReconcile is used to trigger a reconcile on the resource.
66-
OperationAnnotationValueReconcile = "reconcile"
67-
6859
// K8sVersionAnnotation can be used to display the k8s version of the cluster.
6960
K8sVersionAnnotation = GroupName + "/k8sversion"
7061
// ProviderInfoAnnotation can be used to display provider-specific information about the cluster.

api/clusters/v1alpha1/groupversion_info.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ package v1alpha1
55
import (
66
"k8s.io/apimachinery/pkg/runtime/schema"
77
"sigs.k8s.io/controller-runtime/pkg/scheme"
8+
9+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
810
)
911

10-
const ParentGroupName = "openmcp.cloud"
11-
const GroupName = "clusters." + ParentGroupName
12+
const GroupName = "clusters." + apiconst.OpenMCPGroupName
1213

1314
var (
1415
// GroupVersion is group version used to register these objects

api/constants/constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package constants
2+
3+
const (
4+
// OpenMCPGroupName is the base API group name for OpenMCP.
5+
OpenMCPGroupName = "openmcp.cloud"
6+
7+
// ClusterLabel can be used on CRDs to indicate onto which cluster they should be deployed.
8+
ClusterLabel = OpenMCPGroupName + "/cluster"
9+
10+
// OperationAnnotation is used to trigger specific operations on resources.
11+
OperationAnnotation = OpenMCPGroupName + "/operation"
12+
// OperationAnnotationValueIgnore is used to ignore the resource.
13+
OperationAnnotationValueIgnore = "ignore"
14+
// OperationAnnotationValueReconcile is used to trigger a reconcile on the resource.
15+
OperationAnnotationValueReconcile = "reconcile"
16+
)

cmd/openmcp-operator/app/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sigs.k8s.io/yaml"
1111

1212
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
13+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
1314
"github.com/openmcp-project/openmcp-operator/api/crds"
1415
"github.com/openmcp-project/openmcp-operator/api/install"
1516
)
@@ -75,7 +76,7 @@ func (o *InitOptions) Run(ctx context.Context) error {
7576
log.Info("Environment", "value", o.Environment)
7677

7778
// apply CRDs
78-
crdManager := crdutil.NewCRDManager(clustersv1alpha1.ClusterLabel, crds.CRDs)
79+
crdManager := crdutil.NewCRDManager(apiconst.ClusterLabel, crds.CRDs)
7980

8081
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_ONBOARDING, o.Clusters.Onboarding)
8182
crdManager.AddCRDLabelToClusterMapping(clustersv1alpha1.PURPOSE_PLATFORM, o.Clusters.Platform)

internal/controllers/accessrequest/controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
1919
cconst "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1/constants"
20+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
2021
"github.com/openmcp-project/openmcp-operator/internal/config"
2122
)
2223

@@ -72,15 +73,15 @@ func (r *AccessRequestReconciler) reconcile(ctx context.Context, req reconcile.R
7273

7374
// handle operation annotation
7475
if ar.GetAnnotations() != nil {
75-
op, ok := ar.GetAnnotations()[clustersv1alpha1.OperationAnnotation]
76+
op, ok := ar.GetAnnotations()[apiconst.OperationAnnotation]
7677
if ok {
7778
switch op {
78-
case clustersv1alpha1.OperationAnnotationValueIgnore:
79+
case apiconst.OperationAnnotationValueIgnore:
7980
log.Info("Ignoring resource due to ignore operation annotation")
8081
return ReconcileResult{}
81-
case clustersv1alpha1.OperationAnnotationValueReconcile:
82+
case apiconst.OperationAnnotationValueReconcile:
8283
log.Debug("Removing reconcile operation annotation from resource")
83-
if err := ctrlutils.EnsureAnnotation(ctx, r.PlatformCluster.Client(), ar, clustersv1alpha1.OperationAnnotation, "", true, ctrlutils.DELETE); err != nil {
84+
if err := ctrlutils.EnsureAnnotation(ctx, r.PlatformCluster.Client(), ar, apiconst.OperationAnnotation, "", true, ctrlutils.DELETE); err != nil {
8485
return ReconcileResult{ReconcileError: errutils.WithReason(fmt.Errorf("error removing operation annotation: %w", err), cconst.ReasonPlatformClusterInteractionProblem)}
8586
}
8687
}
@@ -193,10 +194,10 @@ func (r *AccessRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
193194
)),
194195
ctrlutils.LabelSelectorPredicate(r.Config.Selector.Completed()),
195196
predicate.Or(
196-
ctrlutils.GotAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueReconcile),
197-
ctrlutils.LostAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueIgnore),
197+
ctrlutils.GotAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueReconcile),
198+
ctrlutils.LostAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueIgnore),
198199
),
199-
predicate.Not(ctrlutils.HasAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueIgnore)),
200+
predicate.Not(ctrlutils.HasAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueIgnore)),
200201
)).
201202
Complete(r)
202203
}

internal/controllers/scheduler/controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
2525
cconst "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1/constants"
26+
apiconst "github.com/openmcp-project/openmcp-operator/api/constants"
2627
"github.com/openmcp-project/openmcp-operator/internal/config"
2728
)
2829

@@ -87,15 +88,15 @@ func (r *ClusterScheduler) reconcile(ctx context.Context, req reconcile.Request)
8788

8889
// handle operation annotation
8990
if cr.GetAnnotations() != nil {
90-
op, ok := cr.GetAnnotations()[clustersv1alpha1.OperationAnnotation]
91+
op, ok := cr.GetAnnotations()[apiconst.OperationAnnotation]
9192
if ok {
9293
switch op {
93-
case clustersv1alpha1.OperationAnnotationValueIgnore:
94+
case apiconst.OperationAnnotationValueIgnore:
9495
log.Info("Ignoring resource due to ignore operation annotation")
9596
return ReconcileResult{}
96-
case clustersv1alpha1.OperationAnnotationValueReconcile:
97+
case apiconst.OperationAnnotationValueReconcile:
9798
log.Debug("Removing reconcile operation annotation from resource")
98-
if err := ctrlutils.EnsureAnnotation(ctx, r.PlatformCluster.Client(), cr, clustersv1alpha1.OperationAnnotation, "", true, ctrlutils.DELETE); err != nil {
99+
if err := ctrlutils.EnsureAnnotation(ctx, r.PlatformCluster.Client(), cr, apiconst.OperationAnnotation, "", true, ctrlutils.DELETE); err != nil {
99100
return ReconcileResult{ReconcileError: errutils.WithReason(fmt.Errorf("error removing operation annotation: %w", err), cconst.ReasonPlatformClusterInteractionProblem)}
100101
}
101102
}
@@ -324,10 +325,10 @@ func (r *ClusterScheduler) SetupWithManager(mgr ctrl.Manager) error {
324325
predicate.Or(
325326
predicate.GenerationChangedPredicate{},
326327
ctrlutils.DeletionTimestampChangedPredicate{},
327-
ctrlutils.GotAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueReconcile),
328-
ctrlutils.LostAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueIgnore),
328+
ctrlutils.GotAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueReconcile),
329+
ctrlutils.LostAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueIgnore),
329330
),
330-
predicate.Not(ctrlutils.HasAnnotationPredicate(clustersv1alpha1.OperationAnnotation, clustersv1alpha1.OperationAnnotationValueIgnore)),
331+
predicate.Not(ctrlutils.HasAnnotationPredicate(apiconst.OperationAnnotation, apiconst.OperationAnnotationValueIgnore)),
331332
)).
332333
Complete(r)
333334
}

0 commit comments

Comments
 (0)