Skip to content

Commit

Permalink
Fix wrong pluralization for claims (#37)
Browse files Browse the repository at this point in the history
* Fix wrong pluralization for claims

* Add reproducing example
  • Loading branch information
undera committed Aug 31, 2023
1 parent 235bc82 commit 1607454
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 7 deletions.
210 changes: 210 additions & 0 deletions examples/issue37.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
---
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: rdss.databaserds.company.com
spec:
group: databaserds.company.com
names:
kind: RDS
plural: rdss
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
location:
type: string
oneOf:
- pattern: '^EU$'
- pattern: '^US$'
dbName:
type: string
allocatedStorage:
type: integer
dbSubnetGroupName:
type: string
dbSubnetGroupNameRef:
type: string
dbSubnetGroupNameSelector:
type: object
instanceClass:
type: string
engine:
type: string
engineVersion:
type: string
publiclyAccessible:
type: boolean
skipFinalSnapshot:
type: boolean
storageEncrypted:
type: boolean
storageType:
type: string
autoGeneratePassword:
type: boolean
username:
type: string
required:
- location
- allocatedStorage
#- dbSubnetGroupName
- dbName
- instanceClass
- publiclyAccessible
served: true
referenceable: true
claimNames:
kind: RDSClaim
plural: rdsclaim
---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: rds-database
spec:
resources:
- name: subnetRDS
base:
apiVersion: rds.aws.upbound.io/v1beta1
kind: SubnetGroup
metadata:
name: crossplane-mmm-subnetgr1
labels:
crossplaneSubnetgroup: myCrossPlaneSubnetGroup
annotations:
crossplane.io/external-name: subgr-osearchm317555
spec:
writeConnectionSecretToRef:
namespace: crossplane-system
name: subnetgroup-connection-secret
providerConfigRef:
name: aws-provider-config
forProvider:
region: eu-west-1
subnetIds:
- subnet-080ad669df9969dd2
- subnet-0f9f5197718cef400
- subnet-026b60e757c368d29
tags:
Name: RDS Subnet group managed by Crossplane
patches:
- fromFieldPath: "metadata.uid"
toFieldPath: "metadata.annotations.crossplane.io/external-name"
transforms:
- type: string
string:
fmt: "%s-xplanesubgroup"
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-connection-secret"
- name: rdsDB
base:
apiVersion: rds.aws.upbound.io/v1beta1
kind: Instance
metadata:
name: crossplane-rds-database
spec:
providerConfigRef:
name: aws-provider-config
writeConnectionSecretToRef:
namespace: crossplane-system
name: crossplane-rds-instance-connection-secret
forProvider:
region: "eu-west-1"
dbName: myrdsdbcrossplane7
allocatedStorage: 10
dbSubnetGroupNameSelector:
matchLabels:
crossplaneSubnetgroup: myCrossPlaneSubnetGroup
instanceClass: "db.t3.small"
engine: postgres
engineVersion: "15.3"
username: adminuser
autoGeneratePassword: true
passwordSecretRef:
namespace: crossplane-system
key: password
publiclyAccessible: false
skipFinalSnapshot: true
storageEncrypted: true
storageType: gp2
patches:
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-postgresql"
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.forProvider.passwordSecretRef.name"
transforms:
- type: string
string:
fmt: "%s-input"
- type: FromCompositeFieldPath
fromFieldPath: "spec.location"
toFieldPath: "spec.forProvider.region"
transforms:
- type: map
map:
EU: "eu-west-1"
US: "us-east-2"
- type: FromCompositeFieldPath
fromFieldPath: "spec.allocatedStorage"
toFieldPath: "spec.forProvider.allocatedStorage"
- type: FromCompositeFieldPath
fromFieldPath: "spec.dbName"
toFieldPath: "spec.forProvider.dbName"
- type: FromCompositeFieldPath
fromFieldPath: "spec.instanceClass"
toFieldPath: "spec.forProvider.instanceClass"
- type: FromCompositeFieldPath
fromFieldPath: "spec.engine"
toFieldPath: "spec.forProvider.engine"
- type: FromCompositeFieldPath
fromFieldPath: "spec.engineVersion"
toFieldPath: "spec.forProvider.engineVersion"
- type: FromCompositeFieldPath
fromFieldPath: "spec.storageType"
toFieldPath: "spec.forProvider.storageType"
readinessChecks:
- type: None
connectionDetails:
- fromFieldPath: "status.atProvider.endpoint"
name: endpoint
- fromFieldPath: "status.atProvider.address"
name: host
- fromFieldPath: "spec.forProvider.username"
name: username
- fromConnectionSecretKey: "attribute.password"
name: password
compositeTypeRef:
apiVersion: databaserds.company.com/v1alpha1
kind: RDS
---
apiVersion: databaserds.company.com/v1alpha1
kind: RDSClaim
metadata:
name: osearchm317555
spec:
location: "EU"
allocatedStorage: 10
dbName: osearchm31755
instanceClass: "db.t3.micro"
engine: postgres
engineVersion: "15.3"
username: adminuser
autoGeneratePassword: true
publiclyAccessible: false
skipFinalSnapshot: true
storageEncrypted: true
storageType: gp2 #gp3 is 20GB and UP
9 changes: 2 additions & 7 deletions pkg/backend/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func (c *Controller) GetClaim(ec echo.Context) error {
}

func (c *Controller) getDynamicResource(ref *v12.ObjectReference, res ConditionedObject) (err error) {
res.SetAnnotations(map[string]string{})

if ref.Name == "" {
condNotFound := xpv1.Condition{
Type: "Found",
Expand Down Expand Up @@ -314,13 +316,6 @@ func (c *Controller) getDynamicResource(ref *v12.ObjectReference, res Conditione
res.SetNamespace(ref.Namespace)
res.SetName(ref.Name)

// we need to guarantee for frontend that "metadata" is in structure
if r, ok := res.(*uxres.Unstructured); ok {
if _, ok := r.Object["metadata"]; !ok {
r.Object["metadata"] = map[string]interface{}{}
}
}

return err
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/backend/crossplane/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (c *crdClient) getPluralKind(ctx context.Context, ref *v1.ObjectReference)
}

for _, xrd := range xrds.Items {
if xrd.Spec.ClaimNames != nil && xrd.Spec.ClaimNames.Kind == ref.Kind && xrd.Spec.Group == ref.GroupVersionKind().Group {
return xrd.Spec.ClaimNames.Plural, nil
}

if xrd.Spec.Names.Kind == ref.Kind && xrd.Spec.Group == ref.GroupVersionKind().Group {
return xrd.Spec.Names.Plural, nil
}
Expand Down

0 comments on commit 1607454

Please sign in to comment.