Skip to content

Commit

Permalink
Merge pull request #96 from vshn/webhooks/deletionProtection
Browse files Browse the repository at this point in the history
Add labels for backend deletionProtection
  • Loading branch information
TheBigLee authored Oct 22, 2024
2 parents fc73d27 + e6eea8a commit 11717d1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pkg/crossplane/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
52 changes: 33 additions & 19 deletions pkg/crossplane/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
44 changes: 25 additions & 19 deletions pkg/crossplane/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
3 changes: 3 additions & 0 deletions testdata/crds/compositemariadbinstances.syn.tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions testdata/crds/compositeredisinstances.syn.tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11717d1

Please sign in to comment.