Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate reference fields for the spec.initProvider of all resources #1046

Merged
merged 3 commits into from
Dec 28, 2023

Conversation

ulucinar
Copy link
Collaborator

@ulucinar ulucinar commented Dec 27, 2023

Description of your changes

Fixes #975
Fixes #994

This PR bumps the upjet to the commit 4cb45f9104ac with @sergenyalcin's changes addressing crossplane/upjet#307 and adds the referencer fields under to spec.initProvider.

This PR also bumps the crossplane-runtime to commit d23a82b3a2f5 to consume crossplane/crossplane-runtime#623. The provider will use Server Side Apply (SSA) patch operations while updating the resolved cross-resource references. The spec.forProvider.vpcConfig of Cluster.eks is converted into an associative list by injecting an index field and its SSA merge strategy is set to map so that the API server will be able to merge the list objects instead of replacing the whole list atomically, effective addressing #975. Please also see crossplane/upjet#308 for more context.

I have:

  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Tested the Cluster.eks resource via the uptest run: https://github.com/upbound/provider-aws/actions/runs/7342098403

Also validated the race condition on the spec.forProvider.vpcConfig[0].subnetIds of Cluster.eks is actually resolved with the P&T function v0.2.1 is used together with a custom build of the upbound/provider-aws from this PR. The composition I've used is as follows:

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: xeks.aws.platform.upbound.io
  labels:
    provider: aws
spec:
  writeConnectionSecretsToNamespace: upbound-system
  compositeTypeRef:
    apiVersion: aws.platform.upbound.io/v1alpha1
    kind: XEKS
  mode: Pipeline
  pipeline:
  - step: patch-and-transform
    functionRef:
      name: function-patch-and-transform
    input:
      apiVersion: pt.fn.crossplane.io/v1beta1
      kind: Resources
      resources:

        - name: cluster
          patches:
          - fromFieldPath: spec.parameters.cLabel
            toFieldPath: spec.forProvider.vpcConfig[0].subnetIdSelector.matchLabels[c]
          base:
            apiVersion: eks.aws.upbound.io/v1beta1
            kind: Cluster
            metadata:
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
                uptest.upbound.io/timeout: "2400"
              name: sample-eks-cluster
              labels:
                testing.upbound.io/example-name: example
            spec:
              forProvider:
                region: us-west-1
                roleArnSelector:
                  matchLabels:
                    a: b
                vpcConfig:
                  - subnetIdSelector:
                      matchLabels:
                        a: b

        - name: cluster-auth
          base:
            apiVersion: eks.aws.upbound.io/v1beta1
            kind: ClusterAuth
            metadata:
              name: auth
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                clusterNameSelector:
                  matchLabels:
                    testing.upbound.io/example-name: example
              writeConnectionSecretToRef:
                name: cluster-conn
                namespace: upbound-system

        - name: role
          base:
            apiVersion: iam.aws.upbound.io/v1beta1
            kind: Role
            metadata:
              name: sample-eks-cluster
              labels:
                a: b
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                assumeRolePolicy: |
                  {
                    "Version": "2012-10-17",
                    "Statement": [
                      {
                        "Effect": "Allow",
                        "Principal": {
                          "Service": "eks.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole"
                      }
                    ]
                  }

        - name: rolepolicyattachment
          base:
            apiVersion: iam.aws.upbound.io/v1beta1
            kind: RolePolicyAttachment
            metadata:
              name: sample-cluster-policy
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                policyArn: arn:aws:iam::aws:policy/AmazonEKSClusterPolicy
                roleSelector:
                  matchLabels:
                    a: b

        - name: subnet-1
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: Subnet
            metadata:
              name: sample-subnet1
              labels:
                a: b
                c: d
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                mapPublicIpOnLaunch: true
                availabilityZone: us-west-1b
                vpcIdSelector:
                  matchLabels:
                    a: b
                cidrBlock: 172.16.10.0/24

        - name: subnet-2
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: Subnet
            metadata:
              name: sample-subnet2
              labels:
                a: b
                c: d
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                mapPublicIpOnLaunch: true
                availabilityZone: us-west-1c
                vpcIdSelector:
                  matchLabels:
                    a: b
                cidrBlock: 172.16.11.0/24

        - name: subnet-private
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: Subnet
            metadata:
              name: private-subnet
              labels:
                a: b
                subnet: private
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                availabilityZone: us-west-1b
                vpcIdSelector:
                  matchLabels:
                    a: b
                cidrBlock: 172.16.12.0/24

        - name: routetable
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: RouteTable
            metadata:
              name: example
              labels:
                a: b
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                tags:
                  Name: example
                vpcIdSelector:
                  matchLabels:
                    a: b

        - name: routetableassocation
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: RouteTableAssociation
            metadata:
              name: example
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                routeTableIdSelector:
                  matchLabels:
                    a: b
                subnetIdSelector:
                  matchLabels:
                    a: b
                    subnet: private

        - name: vpc
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: VPC
            metadata:
              name: sample-vpc
              labels:
                a: b
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                enableDnsHostnames: true
                region: us-west-1
                cidrBlock: 172.16.0.0/16
                tags:
                  Name: DemoVpc

        - name: igw
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: InternetGateway
            metadata:
              name: example
              labels:
                a: b
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                region: us-west-1
                vpcIdSelector:
                  matchLabels:
                    a: b

        - name: defaultroutetable
          base:
            apiVersion: ec2.aws.upbound.io/v1beta1
            kind: DefaultRouteTable
            metadata:
              name: example
              annotations:
                meta.upbound.io/example-id: eks/v1beta1/cluster
            spec:
              forProvider:
                defaultRouteTableIdSelector:
                  matchLabels:
                    a: b
                region: us-west-1
                route:
                  - gatewayIdSelector:
                      matchLabels:
                        a: b
                    cidrBlock: 0.0.0.0/0

- Generate reference fields for the spec.initProvider of all resources.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@ulucinar
Copy link
Collaborator Author

/test-examples="examples/ec2/vpc.yaml"

- Use SSA patch operations while updating resolved cross-resource references.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
…of Cluster.eks

and configure the list's Server Side Apply merge strategy as "map", setting the
list map keys to the set {"index"}.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
@ulucinar
Copy link
Collaborator Author

/test-examples="examples/eks/cluster.yaml"

Copy link
Collaborator

@turkenf turkenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ulucinar, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants