Skip to content

Commit

Permalink
feat(spaces): add initial composition (#1)
Browse files Browse the repository at this point in the history
* feat(spaces): add initial composition

Signed-off-by: Christopher Haar <[email protected]>

* feat(sg): remove sg observe, delete

Signed-off-by: Christopher Haar <[email protected]>

---------

Signed-off-by: Christopher Haar <[email protected]>
  • Loading branch information
haarchri authored Feb 28, 2024
1 parent 015c356 commit 954bd25
Show file tree
Hide file tree
Showing 21 changed files with 1,969 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PLATFORMS ?= linux_amd64

UP_VERSION = v0.24.1
UP_CHANNEL = stable
UPTEST_VERSION = v0.11.0
UPTEST_VERSION = v0.11.1

-include build/makelib/k8s_tools.mk
# ====================================================================================
Expand All @@ -23,7 +23,7 @@ UPTEST_VERSION = v0.11.0
# certain conventions such as the default examples root or package directory.
XPKG_DIR = $(shell pwd)
XPKG_EXAMPLES_DIR = .up/examples
XPKG_IGNORE = .github/workflows/*.yml,.github/workflows/*.yaml,init/*.yaml,examples/flux/*.yaml,examples/*.yaml,examples/argocd/*.yaml,.work/uptest-datasource.yaml
XPKG_IGNORE = .github/workflows/*.yml,.github/workflows/*.yaml,init/*.yaml,examples/*.yaml,.work/uptest-datasource.yaml,examples/**/*.yaml

XPKG_REG_ORGS ?= xpkg.upbound.io/upbound
# NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are
Expand Down Expand Up @@ -64,24 +64,27 @@ build.init: $(UP)
# End to End Testing

# This target requires the following environment variables to be set:
# $ export UPTEST_CLOUD_CREDENTIALS=$(echo "AWS='$(cat ~/.aws/credentials)'\nAZURE='$(cat ~/.azure/credentials.json)'\nGCP='$(cat ~/.gcloud/credentials.json)")
# $ export UPTEST_CLOUD_CREDENTIALS=$(echo "AWS='$(cat ~/.aws/credentials)'\nAZURE='$(cat ~/.azure/credentials.json)'\nGCP='$(cat ~/.gcloud/credentials.json)'\nSPACES='$(cat ~/.gcloud/key.json)'")
uptest: $(UPTEST) $(KUBECTL) $(KUTTL)
@$(INFO) running automated tests
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) $(UPTEST) e2e "${UPTEST_EXAMPLE_LIST}" --data-source="${UPTEST_DATASOURCE_PATH}" --setup-script=test/setup.sh --default-timeout=4800 || $(FAIL)
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) $(UPTEST) e2e "${UPTEST_EXAMPLE_LIST}" --data-source="${UPTEST_DATASOURCE_PATH}" --setup-script=test/setup.sh --default-timeout=4800 ${SKIP_DELETE} || $(FAIL)
@$(OK) running automated tests

# This target requires the following environment variables to be set:
# $ export UPTEST_CLOUD_CREDENTIALS=$(echo "AWS='$(cat ~/.aws/credentials)'\nAZURE='$(cat ~/.azure/credentials.json)'\nGCP='$(cat ~/.gcloud/credentials.json)")
# $ export UPTEST_CLOUD_CREDENTIALS=$(echo "AWS='$(cat ~/.aws/credentials)'\nAZURE='$(cat ~/.azure/credentials.json)'\nGCP='$(cat ~/.gcloud/credentials.json)'\nSPACES='$(cat ~/.gcloud/key.json)'")
e2e: build controlplane.up local.xpkg.deploy.configuration.$(PROJECT_NAME) uptest

render:
crossplane beta render examples/aws-cluster.yaml apis/composition.yaml examples/functions.yaml -r
crossplane beta render examples/azure-cluster.yaml apis/composition.yaml examples/functions.yaml -r
crossplane beta render examples/space.yaml apis/composition.yaml examples/functions.yaml -r
crossplane beta render examples/xr/aws-hostcluster.yaml apis/cluster/composition.yaml examples/functions.yaml -r
crossplane beta render examples/xr/azure-hostcluster.yaml apis/cluster/composition.yaml examples/functions.yaml -r
crossplane beta render examples/xr/gcp-hostcluster.yaml apis/cluster/composition.yaml examples/functions.yaml -r
crossplane beta render examples/xr/space-init.yaml apis/space-init/composition.yaml examples/functions.yaml -r
crossplane beta render examples/xr/space-core.yaml apis/space-core/composition.yaml examples/functions.yaml -r
crossplane beta render examples/aws-host-space.yaml apis/composition.yaml examples/functions.yaml -r

yamllint:
@$(INFO) running yamllint
@yamllint ./apis || $(FAIL)
@$(OK) running yamllint

.PHONY: uptest e2e render yamllint
.PHONY: uptest e2e render yamllint
238 changes: 238 additions & 0 deletions apis/cluster/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xclusters.spaces.platformref.upbound.io
spec:
writeConnectionSecretsToNamespace: upbound-system
compositeTypeRef:
apiVersion: spaces.platformref.upbound.io/v1alpha1
kind: XCluster
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
name: upboundcare-function-conditional-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
- name: XNetworkAWS
condition: observed.composite.resource.spec.parameters.cloud == "aws"
base:
apiVersion: aws.platform.upbound.io/v1alpha1
kind: XNetwork
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.networkSelector
toFieldPath: spec.compositionSelector.matchLabels[type]
- type: ToCompositeFieldPath
fromFieldPath: status.subnetIds
policy:
fromFieldPath: Required
toFieldPath: status.subnetIds

- name: XEKS
condition: observed.composite.resource.spec.parameters.cloud == "aws"
base:
apiVersion: aws.platform.upbound.io/v1alpha1
kind: XEKS
connectionDetails:
- type: FromConnectionSecretKey
fromConnectionSecretKey: kubeconfig
name: kubeconfig
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: metadata.labels[xeks.aws.platform.upbound.io/cluster-id]
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: metadata.annotations[crossplane.io/external-name]
- type: FromCompositeFieldPath
fromFieldPath: metadata.uid
toFieldPath: spec.writeConnectionSecretToRef.name
transforms:
- type: string
string:
fmt: '%s-eks'
type: Format
- type: FromCompositeFieldPath
fromFieldPath: spec.writeConnectionSecretToRef.namespace
toFieldPath: spec.writeConnectionSecretToRef.namespace
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.version
toFieldPath: spec.parameters.version
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.count
toFieldPath: spec.parameters.nodes.count
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.instanceType
toFieldPath: spec.parameters.nodes.instanceType
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.iam.roleArn
toFieldPath: spec.parameters.iam.roleArn
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.iam.userArn
toFieldPath: spec.parameters.iam.userArn

- name: XNetworkAZURE
condition: observed.composite.resource.spec.parameters.cloud == "azure"
base:
apiVersion: azure.platform.upbound.io/v1alpha1
kind: XNetwork
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.networkSelector
toFieldPath: spec.compositionSelector.matchLabels[type]

- name: XAKS
condition: observed.composite.resource.spec.parameters.cloud == "azure"
base:
apiVersion: azure.platform.upbound.io/v1alpha1
kind: XAKS
connectionDetails:
- type: FromConnectionSecretKey
fromConnectionSecretKey: kubeconfig
name: kubeconfig
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: metadata.labels[xaks.azure.platform.upbound.io/cluster-id]
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: metadata.uid
toFieldPath: spec.writeConnectionSecretToRef.name
transforms:
- type: string
string:
fmt: '%s-aks'
type: Format
- type: FromCompositeFieldPath
fromFieldPath: spec.writeConnectionSecretToRef.namespace
toFieldPath: spec.writeConnectionSecretToRef.namespace
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.version
toFieldPath: spec.parameters.version
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.count
toFieldPath: spec.parameters.nodes.count
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.instanceType
toFieldPath: spec.parameters.nodes.instanceType

- name: XNetworkGCP
condition: observed.composite.resource.spec.parameters.cloud == "gcp"
base:
apiVersion: gcp.platform.upbound.io/v1alpha1
kind: XNetwork
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.networkSelector
toFieldPath: spec.compositionSelector.matchLabels[type]

- name: XGKE
condition: observed.composite.resource.spec.parameters.cloud == "gcp"
base:
apiVersion: gcp.platform.upbound.io/v1alpha1
kind: XGKE
connectionDetails:
- type: FromConnectionSecretKey
fromConnectionSecretKey: kubeconfig
name: kubeconfig
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: metadata.labels[xgke.gcp.platform.upbound.io/cluster-id]
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.region
toFieldPath: spec.parameters.region
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: metadata.annotations[crossplane.io/external-name]
- type: FromCompositeFieldPath
fromFieldPath: metadata.uid
toFieldPath: spec.writeConnectionSecretToRef.name
transforms:
- type: string
string:
fmt: '%s-gke'
type: Format
- type: FromCompositeFieldPath
fromFieldPath: spec.writeConnectionSecretToRef.namespace
toFieldPath: spec.writeConnectionSecretToRef.namespace
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.version
toFieldPath: spec.parameters.version
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.count
toFieldPath: spec.parameters.nodes.count
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.nodes.instanceType
toFieldPath: spec.parameters.nodes.instanceType
Loading

0 comments on commit 954bd25

Please sign in to comment.