From d54bb40b58c22b75b94e5e78cad40f3b62447462 Mon Sep 17 00:00:00 2001 From: Jonas Hecht Date: Mon, 8 May 2023 18:26:16 +0200 Subject: [PATCH] #12: Beginning to integrate the upbound official Upjet generated AWS provider --- .github/workflows/provision.yml | 12 ++--- README.md | 28 +++++----- .../s3/claim.yaml | 0 .../s3/composition.yaml | 0 .../s3/crossplane.yaml | 0 .../s3/definition.yaml | 0 provider-aws-upbound/s3/claim.yaml | 20 +++++++ .../s3/composition-try-using-new-s3-sec.yaml | 0 provider-aws-upbound/s3/crossplane.yaml | 10 ++++ provider-aws-upbound/s3/definition.yaml | 52 +++++++++++++++++++ .../storageaccount/claim.yaml | 0 .../storageaccount/composition.yaml | 0 .../storageaccount/definition.yaml | 0 13 files changed, 102 insertions(+), 20 deletions(-) rename {aws => provider-aws-crossplane-contrib}/s3/claim.yaml (100%) rename {aws => provider-aws-crossplane-contrib}/s3/composition.yaml (100%) rename {aws => provider-aws-crossplane-contrib}/s3/crossplane.yaml (100%) rename {aws => provider-aws-crossplane-contrib}/s3/definition.yaml (100%) create mode 100644 provider-aws-upbound/s3/claim.yaml rename {aws => provider-aws-upbound}/s3/composition-try-using-new-s3-sec.yaml (100%) create mode 100644 provider-aws-upbound/s3/crossplane.yaml create mode 100644 provider-aws-upbound/s3/definition.yaml rename {azure => provider-azure-crossplane-contrib}/storageaccount/claim.yaml (100%) rename {azure => provider-azure-crossplane-contrib}/storageaccount/composition.yaml (100%) rename {azure => provider-azure-crossplane-contrib}/storageaccount/definition.yaml (100%) diff --git a/.github/workflows/provision.yml b/.github/workflows/provision.yml index 5734e9b..76c3de3 100644 --- a/.github/workflows/provision.yml +++ b/.github/workflows/provision.yml @@ -119,17 +119,17 @@ jobs: - name: AWS -> Create XRD, Composite & Claim to create S3 Bucket run: | echo "### Create CompositeResourceDefinition (XRD)" - kubectl apply -f aws/s3/definition.yaml + kubectl apply -f provider-aws-crossplane-contrib/s3/definition.yaml kubectl get xrd echo "### Wait for XRD to become Offered" kubectl wait --for=condition=Offered --timeout=120s xrd xobjectstorages.crossplane.jonashackt.io echo "### Create Composition" - kubectl apply -f aws/s3/composition.yaml + kubectl apply -f provider-aws-crossplane-contrib/s3/composition.yaml echo "### Create Claim, which should create S3 Bucket" - kubectl apply -f aws/s3/claim.yaml + kubectl apply -f provider-aws-crossplane-contrib/s3/claim.yaml echo "### Wait until Claim & XR (Composite) are ready" kubectl wait --for=condition=ready --timeout=120s claim managed-s3 @@ -156,17 +156,17 @@ jobs: - name: Azure -> Create XRD, Composite & Claim to create ResourceGroup & StorageAccount run: | echo "### Create CompositeResourceDefinition (XRD)" - kubectl apply -f azure/storageaccount/definition.yaml + kubectl apply -f provider-azure-crossplane-contrib/storageaccount/definition.yaml kubectl get xrd echo "### Wait for XRD to become Offered" kubectl wait --for=condition=Offered --timeout=120s xrd xobjectstorages.crossplane.jonashackt.io echo "### Create Composition" - kubectl apply -f azure/storageaccount/composition.yaml + kubectl apply -f provider-azure-crossplane-contrib/storageaccount/composition.yaml echo "### Create Claim, which should create ResourceGroup & StorageAccount" - kubectl apply -f azure/storageaccount/claim.yaml + kubectl apply -f provider-azure-crossplane-contrib/storageaccount/claim.yaml echo "### Show crossplane overall status" kubectl get crossplane diff --git a/README.md b/README.md index f362c9e..44adaf7 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ Note that Crossplane will be automatically extended this section. Therefore the status.connectionDetails -So our Composite Resource Definition (XRD) for our S3 Bucket could look like [aws/s3/definition.yaml](aws/s3/definition.yaml): +So our Composite Resource Definition (XRD) for our S3 Bucket could look like [provider-aws-crossplane-contrib/s3/definition.yaml](provider-aws-crossplane-contrib/s3/definition.yaml): ```yaml --- @@ -402,7 +402,7 @@ spec: Install the XRD into our cluster with: ```shell -kubectl apply -f aws/s3/definition.yaml +kubectl apply -f provider-aws-crossplane-contrib/s3/definition.yaml ``` We can double check the CRDs beeing created with `kubectl get crds` and filter them using `grep` to our group name `crossplane.jonashackt.io`: @@ -420,7 +420,7 @@ The main work in Crossplane has to be done crafting the Compositions. This is be Detailled docs to many of the possible manifest configurations can be found here https://crossplane.io/docs/v1.8/reference/composition.html#compositions -A Composite to manage an S3 Bucket in AWS with public access for static website hosting could for example look like this [aws/s3/composition.yaml](aws/s3/composition.yaml): +A Composite to manage an S3 Bucket in AWS with public access for static website hosting could for example look like this [provider-aws-crossplane-contrib/s3/composition.yaml](provider-aws-crossplane-contrib/s3/composition.yaml): ```yaml --- @@ -482,7 +482,7 @@ spec: Install our Composition with ```shell -kubectl apply -f aws/s3/composition.yaml +kubectl apply -f provider-aws-crossplane-contrib/s3/composition.yaml ``` @@ -493,7 +493,7 @@ Crossplane could look quite intimidating when having a first look. There are few https://crossplane.io/docs/v1.8/reference/composition.html#composite-resources-and-claims -Since we want to create a S3 Bucket, here's an suggestion for an [claim.yaml](aws/s3/claim.yaml): +Since we want to create a S3 Bucket, here's an suggestion for an [claim.yaml](provider-aws-crossplane-contrib/s3/claim.yaml): ```yaml --- @@ -521,7 +521,7 @@ spec: Testdrive with: ```shell -kubectl apply -f aws/s3/claim.yaml +kubectl apply -f provider-aws-crossplane-contrib/s3/claim.yaml ``` When somthing goes wrong with the validation, this could look like this: @@ -822,7 +822,7 @@ https://doc.crds.dev/github.com/crossplane/provider-azure/azure.crossplane.io/Re ### Defining a CompositeResourceDefinition (XRD) for our Storage Account -So our Composite Resource Definition (XRD) for our Storage Account could look like [azure/storageaccount/definition.yaml](azure/storageaccount/definition.yaml): +So our Composite Resource Definition (XRD) for our Storage Account could look like [provider-azure-crossplane-contrib/storageaccount/definition.yaml](provider-azure-crossplane-contrib/storageaccount/definition.yaml): ```yaml --- @@ -872,7 +872,7 @@ spec: Install the XRD into our cluster with: ```shell -kubectl apply -f azure/storageaccount/definition.yaml +kubectl apply -f provider-azure-crossplane-contrib/storageaccount/definition.yaml ``` Let's wait for the XRD to become `Offered`: @@ -884,7 +884,7 @@ kubectl wait --for=condition=Offered --timeout=120s xrd xstoragesazure.crossplan ### Craft a Composition to manage our needed cloud resources -A Composite to manage an Storage Account in Azure with public access for static website hosting could for example look like this [azure/storageaccount/composition.yaml](azure/storageaccount/composition.yaml): +A Composite to manage an Storage Account in Azure with public access for static website hosting could for example look like this [provider-azure-crossplane-contrib/storageaccount/composition.yaml](provider-azure-crossplane-contrib/storageaccount/composition.yaml): ```yaml --- @@ -939,14 +939,14 @@ spec: Install our Composition with ```shell -kubectl apply -f azure/storageaccount/composition.yaml +kubectl apply -f provider-azure-crossplane-contrib/storageaccount/composition.yaml ``` ### Craft a Composite Resource (XR) or Claim (XRC) -Since we want to create a Storage Account, here's an suggestion for an [claim.yaml](azure/storageaccount/claim.yaml): +Since we want to create a Storage Account, here's an suggestion for an [claim.yaml](provider-azure-crossplane-contrib/storageaccount/claim.yaml): ```yaml --- @@ -968,7 +968,7 @@ spec: Testdrive with ```shell -kubectl apply -f azure/storageaccount/claim.yaml +kubectl apply -f provider-azure-crossplane-contrib/storageaccount/claim.yaml ``` Now have a look into the Azure Portal. Our Resource Group should show up: @@ -1047,7 +1047,7 @@ Therefore we need a `crossplane.yaml` file as described in https://crossplane.io See also https://crossplane.io/docs/v1.8/concepts/packages.html#configuration-packages -Our [aws/s3/crossplane.yaml](aws/s3/crossplane.yaml) is of `kind: Configuration` and defines the minimum crossplane version needed alongside the crossplane AWS provider: +Our [provider-aws-crossplane-contrib/s3/crossplane.yaml](provider-aws-crossplane-contrib/s3/crossplane.yaml) is of `kind: Configuration` and defines the minimum crossplane version needed alongside the crossplane AWS provider: ```yaml apiVersion: meta.pkg.crossplane.io/v1 @@ -1075,7 +1075,7 @@ Really strange, getting ```shell kubectl crossplane build configuration -kubectl crossplane: error: failed to build package: failed to parse package: {path:/Users/jonashecht/dev/kubernetes/crossplane-kind-eks/aws/s3/composition.yaml position:0}: no kind "S3Bucket" is registered for version "crossplane.jonashackt.io/v1alpha1" in scheme "/home/runner/work/crossplane/crossplane/internal/xpkg/scheme.go:47" +kubectl crossplane: error: failed to build package: failed to parse package: {path:/Users/jonashecht/dev/kubernetes/crossplane-awws-azure/provider-aws-crossplane-contrib/s3/composition.yaml position:0}: no kind "S3Bucket" is registered for version "crossplane.jonashackt.io/v1alpha1" in scheme "/home/runner/work/crossplane/crossplane/internal/xpkg/scheme.go:47" ``` diff --git a/aws/s3/claim.yaml b/provider-aws-crossplane-contrib/s3/claim.yaml similarity index 100% rename from aws/s3/claim.yaml rename to provider-aws-crossplane-contrib/s3/claim.yaml diff --git a/aws/s3/composition.yaml b/provider-aws-crossplane-contrib/s3/composition.yaml similarity index 100% rename from aws/s3/composition.yaml rename to provider-aws-crossplane-contrib/s3/composition.yaml diff --git a/aws/s3/crossplane.yaml b/provider-aws-crossplane-contrib/s3/crossplane.yaml similarity index 100% rename from aws/s3/crossplane.yaml rename to provider-aws-crossplane-contrib/s3/crossplane.yaml diff --git a/aws/s3/definition.yaml b/provider-aws-crossplane-contrib/s3/definition.yaml similarity index 100% rename from aws/s3/definition.yaml rename to provider-aws-crossplane-contrib/s3/definition.yaml diff --git a/provider-aws-upbound/s3/claim.yaml b/provider-aws-upbound/s3/claim.yaml new file mode 100644 index 0000000..b2f321d --- /dev/null +++ b/provider-aws-upbound/s3/claim.yaml @@ -0,0 +1,20 @@ +--- +# Use the spec.group/spec.versions[0].name defined in the XRD +apiVersion: crossplane.jonashackt.io/v1alpha1 +# Use the spec.claimName or spec.name specified in the XRD +kind: ObjectStorage +metadata: + # Only claims are namespaced, unlike XRs. + namespace: default + name: managed-s3 +spec: + # The compositionRef specifies which Composition this XR will use to compose + # resources when it is created, updated, or deleted. + compositionRef: + name: objectstorage-composition + + # Parameters for the Composition to provide the Managed Resources (MR) with + # to create the actual infrastructure components + parameters: + bucketName: microservice-ui-nuxt-js-static-bucket2 + region: eu-central-1 diff --git a/aws/s3/composition-try-using-new-s3-sec.yaml b/provider-aws-upbound/s3/composition-try-using-new-s3-sec.yaml similarity index 100% rename from aws/s3/composition-try-using-new-s3-sec.yaml rename to provider-aws-upbound/s3/composition-try-using-new-s3-sec.yaml diff --git a/provider-aws-upbound/s3/crossplane.yaml b/provider-aws-upbound/s3/crossplane.yaml new file mode 100644 index 0000000..9c459af --- /dev/null +++ b/provider-aws-upbound/s3/crossplane.yaml @@ -0,0 +1,10 @@ +apiVersion: meta.pkg.crossplane.io/v1 +kind: Configuration +metadata: + name: s3-bucket-example +spec: + crossplane: + version: ">=v1.9" + dependsOn: + - provider: crossplanecontrib/provider-aws + version: ">=v0.33.0" diff --git a/provider-aws-upbound/s3/definition.yaml b/provider-aws-upbound/s3/definition.yaml new file mode 100644 index 0000000..e1b8204 --- /dev/null +++ b/provider-aws-upbound/s3/definition.yaml @@ -0,0 +1,52 @@ +--- +apiVersion: apiextensions.crossplane.io/v1 +kind: CompositeResourceDefinition +metadata: + # XRDs must be named 'x.' + name: xobjectstorages.crossplane.jonashackt.io +spec: + # This XRD defines an XR in the 'crossplane.jonashackt.io' API group. + # The XR or Claim must use this group together with the spec.versions[0].name as it's apiVersion, like this: + # 'crossplane.jonashackt.io/v1alpha1' + group: crossplane.jonashackt.io + + # XR names should always be prefixed with an 'X' + names: + kind: XObjectStorage + plural: xobjectstorages + # This type of XR offers a claim, which should have the same name without the 'X' prefix + claimNames: + kind: ObjectStorage + plural: objectstorages + + # default Composition when none is specified (must match metadata.name of a provided Composition) + # e.g. in composition.yaml + defaultCompositionRef: + name: objectstorage-composition + + versions: + - name: v1alpha1 + served: true + referenceable: true + # OpenAPI schema (like the one used by Kubernetes CRDs). Determines what fields + # the XR (and claim) will have. Will be automatically extended by crossplane. + # See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/ + # for full CRD documentation and guide on how to write OpenAPI schemas + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + # We define 2 needed parameters here one has to provide as XR or Claim spec.parameters + properties: + parameters: + type: object + properties: + bucketName: + type: string + region: + type: string + required: + - bucketName + - region \ No newline at end of file diff --git a/azure/storageaccount/claim.yaml b/provider-azure-crossplane-contrib/storageaccount/claim.yaml similarity index 100% rename from azure/storageaccount/claim.yaml rename to provider-azure-crossplane-contrib/storageaccount/claim.yaml diff --git a/azure/storageaccount/composition.yaml b/provider-azure-crossplane-contrib/storageaccount/composition.yaml similarity index 100% rename from azure/storageaccount/composition.yaml rename to provider-azure-crossplane-contrib/storageaccount/composition.yaml diff --git a/azure/storageaccount/definition.yaml b/provider-azure-crossplane-contrib/storageaccount/definition.yaml similarity index 100% rename from azure/storageaccount/definition.yaml rename to provider-azure-crossplane-contrib/storageaccount/definition.yaml