diff --git a/pkg/crossplane/client.go b/pkg/crossplane/client.go index f1a06fc..71bec9d 100644 --- a/pkg/crossplane/client.go +++ b/pkg/crossplane/client.go @@ -268,7 +268,7 @@ func (cp Crossplane) prepareLabels(rctx *reqcontext.ReqContext, id string, plan } // Copy relevant labels from plan - planLabels := []string{ServiceIDLabel, ServiceNameLabel, PlanNameLabel, ClusterLabel, SLALabel} + planLabels := []string{ServiceIDLabel, ServiceNameLabel, PlanNameLabel, ClusterLabel, SLALabel, OwnerApiVersionLabel, OwnerGroupLabel, OwnerKindLabel} for _, name := range planLabels { l[name] = plan.Composition.Labels[name] } diff --git a/pkg/crossplane/metadata.go b/pkg/crossplane/metadata.go index 15aa0a0..cd1df40 100644 --- a/pkg/crossplane/metadata.go +++ b/pkg/crossplane/metadata.go @@ -9,6 +9,7 @@ import ( const ( // SynToolsBase is the base domain SynToolsBase = "service.syn.tools" + AppcatBase = "appcat.vshn.io" // DescriptionAnnotation of the instance DescriptionAnnotation = SynToolsBase + "/description" @@ -43,35 +44,48 @@ const ( DeletedLabel = SynToolsBase + "/deleted" // PrincipalLabel stores the username of the entity (person or system) that created the respective resource PrincipalLabel = SynToolsBase + "/principal" + + //OwnerApiVersionLabel stores the apiVersion of the composite + OwnerApiVersionLabel = AppcatBase + "/ownerapiversion" + //OwnerGroupLabel stores the group of the composite + OwnerGroupLabel = AppcatBase + "/ownergroup" + //OwnerKindLabel stores the kind of the composite + OwnerKindLabel = AppcatBase + "/ownerkind" ) // Labels provides uniform access to parsed labels. type Labels struct { - ServiceName ServiceName - ServiceID string - PlanName string - PlanSize string - InstanceID string - ParentID string - SLA string - Bindable bool - Updatable bool - Deleted bool + ServiceName ServiceName + ServiceID string + PlanName string + PlanSize string + InstanceID string + ParentID string + SLA string + Bindable bool + Updatable bool + Deleted bool + OwnerApiVersion string + OwnerGroup string + OwnerKind string } func parseLabels(l map[string]string) (*Labels, error) { name := l[PlanNameLabel] sla := l[SLALabel] md := Labels{ - ServiceName: ServiceName(l[ServiceNameLabel]), - ServiceID: l[ServiceIDLabel], - PlanName: name, - PlanSize: getPlanSize(name, sla), - InstanceID: l[InstanceIDLabel], - ParentID: l[ParentIDLabel], - SLA: sla, - Bindable: true, - Deleted: false, + ServiceName: ServiceName(l[ServiceNameLabel]), + ServiceID: l[ServiceIDLabel], + PlanName: name, + PlanSize: getPlanSize(name, sla), + InstanceID: l[InstanceIDLabel], + ParentID: l[ParentIDLabel], + SLA: sla, + Bindable: true, + Deleted: false, + OwnerApiVersion: l[OwnerApiVersionLabel], + OwnerGroup: l[OwnerGroupLabel], + OwnerKind: l[OwnerKindLabel], } var err error diff --git a/pkg/crossplane/metadata_test.go b/pkg/crossplane/metadata_test.go index 6fb2778..8a4d25a 100644 --- a/pkg/crossplane/metadata_test.go +++ b/pkg/crossplane/metadata_test.go @@ -33,27 +33,33 @@ func Test_parseLabels(t *testing.T) { { name: "parses labels successfully", labels: map[string]string{ - ServiceNameLabel: string(RedisService), - ServiceIDLabel: "sid", - PlanNameLabel: "pname-premium", - SLALabel: "premium", - InstanceIDLabel: "iid", - ParentIDLabel: "pid", - BindableLabel: "false", - UpdatableLabel: "true", - DeletedLabel: "true", + ServiceNameLabel: string(RedisService), + ServiceIDLabel: "sid", + PlanNameLabel: "pname-premium", + SLALabel: "premium", + InstanceIDLabel: "iid", + ParentIDLabel: "pid", + BindableLabel: "false", + UpdatableLabel: "true", + DeletedLabel: "true", + OwnerApiVersionLabel: "v1alpha1", + OwnerGroupLabel: "syn.tools", + OwnerKindLabel: "CompositeFooInstance", }, want: &Labels{ - ServiceName: RedisService, - ServiceID: "sid", - PlanName: "pname-premium", - PlanSize: "pname", - SLA: "premium", - InstanceID: "iid", - ParentID: "pid", - Bindable: false, - Updatable: true, - Deleted: true, + ServiceName: RedisService, + ServiceID: "sid", + PlanName: "pname-premium", + PlanSize: "pname", + SLA: "premium", + InstanceID: "iid", + ParentID: "pid", + Bindable: false, + Updatable: true, + Deleted: true, + OwnerApiVersion: "v1alpha1", + OwnerGroup: "syn.tools", + OwnerKind: "CompositeFooInstance", }, wantErr: false, }, diff --git a/testdata/crds/compositemariadbinstances.syn.tools.yaml b/testdata/crds/compositemariadbinstances.syn.tools.yaml index dd3d68f..9e21999 100644 --- a/testdata/crds/compositemariadbinstances.syn.tools.yaml +++ b/testdata/crds/compositemariadbinstances.syn.tools.yaml @@ -7,6 +7,9 @@ metadata: service.syn.tools/id: 5e7ee9b8-3f5e-4081-a91f-e0cd98827e84 service.syn.tools/name: mariadb-k8s service.syn.tools/updatable: "true" + appcat.vshn.io/ownerapiversion: v1alpha1 + appcat.vshn.io/ownergroup: syn.tools + appcat.vshn.io/ownerkind: CompositeMariaDBInstance name: compositemariadbinstances.syn.tools ownerReferences: - apiVersion: apiextensions.crossplane.io/v1 diff --git a/testdata/crds/compositeredisinstances.syn.tools.yaml b/testdata/crds/compositeredisinstances.syn.tools.yaml index ad60af7..28c394a 100644 --- a/testdata/crds/compositeredisinstances.syn.tools.yaml +++ b/testdata/crds/compositeredisinstances.syn.tools.yaml @@ -6,6 +6,9 @@ metadata: service.syn.tools/id: 8d4b8039-6bcc-4f68-98f0-0e8efa5ab0e2 service.syn.tools/name: redis-k8s service.syn.tools/updatable: "true" + appcat.vshn.io/ownerapiversion: v1alpha1 + appcat.vshn.io/ownergroup: syn.tools + appcat.vshn.io/ownerkind: CompositeMariaDBInstance name: compositeredisinstances.syn.tools ownerReferences: - apiVersion: apiextensions.crossplane.io/v1