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

feat(functions): use configurations, update to functions #49

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
"helpers:pinGitHubActionDigests",
":semanticCommits"
],
"rebaseWhen": "conflicted",
"prConcurrentLimit": 5,
"baseBranches": ["main"],
"labels": ["automated"],
"customManagers": [
{
"customType": "regex",
"description": "Bump up version in the Makefile",
"fileMatch": ["^Makefile$"],
"matchStrings": [
"UP_VERSION = (?<currentValue>.*?)\\n"
],
"datasourceTemplate": "github-releases",
"depNameTemplate": "upbound/up",
}, {
"customType": "regex",
"description": "Bump uptest version in the Makefile",
"fileMatch": ["^Makefile$"],
"matchStrings": [
"UPTEST_VERSION = (?<currentValue>.*?)\\n"
],
"datasourceTemplate": "github-releases",
"depNameTemplate": "upbound/uptest",
}, {
"customType": "regex",
"description": "Bump providers/functions/configurations in crossplane.yaml",
"fileMatch": ["crossplane.yaml"],
"matchStrings": [
"#\\s*renovate:\\s*datasource=(?<datasource>[^\\s]+)\\s+depName=(?<depName>[^\\s]+)\\s*\\n\\s*version:\\s*\"(?<currentValue>[^\"]+)\""
],
"datasourceTemplate": "{{{datasource}}}",
"depNameTemplate": "{{{depName}}}",
}
],
}
15 changes: 15 additions & 0 deletions .github/workflows/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: yamllint
on: [pull_request]
jobs:
yamllint:
name: runner / yamllint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: yamllint
uses: reviewdog/action-yamllint@v1.9.0
with:
reporter: github-pr-review
filter_mode: nofilter
yamllint_flags: 'apis/'
fail_on_error: true
5 changes: 5 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends: default

rules:
line-length: disable
document-start: disable
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ PLATFORMS ?= linux_amd64
# ====================================================================================
# Setup Kubernetes tools

UP_VERSION = v0.14.0
UP_VERSION = v0.21.0
UP_CHANNEL = stable
UPTEST_VERSION = v0.2.1
UPTEST_VERSION = v0.9.0
haarchri marked this conversation as resolved.
Show resolved Hide resolved

-include build/makelib/k8s_tools.mk
# ====================================================================================
# Setup XPKG
XPKG_DIR = $(shell pwd)
XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml
XPKG_REG_ORGS ?= xpkg.upbound.io/upbound
# NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are
# inferred.
Expand All @@ -26,6 +28,7 @@ XPKGS = $(PROJECT_NAME)
-include build/makelib/xpkg.mk

CROSSPLANE_NAMESPACE = upbound-system
CROSSPLANE_ARGS = "--enable-usages"
-include build/makelib/local.xpkg.mk
-include build/makelib/controlplane.mk

Expand Down Expand Up @@ -59,11 +62,19 @@ build.init: $(UP)
# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat gcp-sa.json)
uptest: $(UPTEST) $(KUBECTL) $(KUTTL)
@$(INFO) running automated tests
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e examples/cluster-claim.yaml,examples/postgres-claim.yaml --setup-script=test/setup.sh --default-timeout=3600 || $(FAIL)
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) $(UPTEST) e2e examples/cluster-claim.yaml,examples/postgres-claim.yaml --setup-script=test/setup.sh --default-timeout=3600 || $(FAIL)
@$(OK) running automated tests

# This target requires the following environment variables to be set:
# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat gcp-sa.json)
e2e: build controlplane.up local.xpkg.deploy.configuration.$(PROJECT_NAME) uptest

.PHONY: uptest e2e
render:
crossplane beta render examples/cluster-claim.yaml apis/cluster/composition.yaml examples/functions.yaml -r

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

.PHONY: uptest e2e render yamllint
60 changes: 32 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ This platform provides APIs to provision fully configured GKE clusters, with
secure networking, and stateful cloud services (Cloud SQL for PostgreSQL) designed to securely
connect to the nodes in each GKE cluster — all composed using cloud service
primitives from the [Official Upbound GCP
Provider](https://marketplace.upbound.io/providers/upbound/provider-gcp). App
Provider](https://marketplace.upbound.io/providers/upbound/provider-family-gcp/). App
deployments can securely connect to the infrastructure they need using secrets
distributed directly to the app namespace.

## Overview

This reference platform defines a custom API for creating an GKE cluster
([XCluster](package/cluster/definition.yaml)) which includes the actual GKE
cluster, a network fabric and Prometheus and other cluster services
([XServices](package/cluster/composition.yaml)). Additionally it defines a
custom API for provisioning Postgres Databases
([XPostgreSQLInstance](package/database/postgres/definition.yaml)).
This reference platform outlines a specialized API for generating an GKE cluster
([XCluster](apis/cluster/definition.yaml)) that incorporates XRs from the specified configurations:

* [upbound-configuration-app](https://github.com/upbound/configuration-app)
* [upbound-configuration-gcp-database](https://github.com/upbound/configuration-gcp-database)
* [upbound-configuration-gcp-gke](https://github.com/upbound/configuration-gcp-gke)
* [upbound-configuration-gcp-network](https://github.com/upbound/configuration-gcp-network)
* [upbound-configuration-gitops-flux](https://github.com/upbound/configuration-gitops-flux)
* [upbound-configuration-observability-oss](https://github.com/upbound/configuration-observability-oss)


```mermaid
Expand Down Expand Up @@ -55,7 +58,7 @@ style Postgres.MRs color:#000,fill:#81CABB,stroke:#000,stroke-width:2px
```

Learn more about Composite Resources in the [Crossplane
Docs](https://crossplane.io/docs/v1.9/concepts/composition.html).
Docs](https://docs.crossplane.io/latest/concepts/compositions/).

## Quickstart

Expand Down Expand Up @@ -98,11 +101,11 @@ kubectl get all -n upbound-system
### Install the GCP Reference Platform

Now you can install this reference platform. It's packaged as a [Crossplane
configuration package](https://crossplane.io/docs/v1.9/concepts/packages.html)
so there is a single command to install this package:
configuration package](https://docs.crossplane.io/latest/concepts/packages/)
so there is a single command to install it:

```console
up ctp configuration install xpkg.upbound.io/upbound/platform-ref-gcp:v0.3.0
up ctp configuration install xpkg.upbound.io/upbound/platform-ref-gcp:v0.5.0
```

Validate the install by inspecting the provider and configuration packages:
Expand Down Expand Up @@ -210,22 +213,28 @@ To delete the provisioned resources, you would simply delete the claims again:
kubectl delete -f examples/cluster-claim.yaml,examples/postgres-claim.yaml
```

**NOTE**: until [ordered
deletion](https://github.com/crossplane/crossplane/issues/3393) is implemented
in core Crossplane, we have to manually cleanup Helm Release and SQL User object
fist:

```console
kubectl delete release.helm.crossplane.io ${release_name}
kubectl delete user.sql.gcp.upbound.io ${sql_user_name}
```

To uninstall the provider & platform configuration:

```console
kubectl delete configurations.pkg.crossplane.io upbound-platform-ref-gcp
kubectl delete providers.pkg.crossplane.io upbound-provider-gcp
kubectl delete providers.pkg.crossplane.io crossplane-contrib-provider-helm
kubectl delete configurations.pkg.crossplane.io upbound-configuration-app
kubectl delete configurations.pkg.crossplane.io upbound-configuration-gcp-database
kubectl delete configurations.pkg.crossplane.io upbound-configuration-gcp-gke
kubectl delete configurations.pkg.crossplane.io upbound-configuration-gcp-network
kubectl delete configurations.pkg.crossplane.io upbound-configuration-gitops-flux
kubectl delete configurations.pkg.crossplane.io upbound-configuration-observability-oss

kubectl delete provider.pkg.crossplane.io crossplane-contrib-provider-helm
kubectl delete provider.pkg.crossplane.io crossplane-contrib-provider-kubernetes
kubectl delete provider.pkg.crossplane.io grafana-provider-grafana
kubectl delete provider.pkg.crossplane.io upbound-provider-family-gcp
kubectl delete provider.pkg.crossplane.io upbound-provider-gcp-cloudplatform
kubectl delete provider.pkg.crossplane.io upbound-provider-gcp-compute
kubectl delete provider.pkg.crossplane.io upbound-provider-gcp-container
kubectl delete provider.pkg.crossplane.io upbound-provider-gcp-servicenetworking
kubectl delete provider.pkg.crossplane.io upbound-provider-gcp-sql

kubectl delete function.pkg.crossplane.io upbound-function-patch-and-transform
```

## Customize for your Organization
Expand Down Expand Up @@ -259,11 +268,6 @@ To make your changes clone this repository:
git clone https://github.com/upbound/platform-ref-gcp.git $PLATFORM && cd $PLATFORM
```

In the [GKE composition](package/cluster/gke/composition.yaml) find the
`location` definitions and change them from `us-west2` to `europe-central2`. Also find the
`autoscaling[0].maxNodeCount` and change it from `3` to `10`.


### Build and push your platform

To share your new platform you need to build and distribute this package.
Expand Down
173 changes: 173 additions & 0 deletions apis/cluster/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xclusters.gcp.platformref.upbound.io
spec:
writeConnectionSecretsToNamespace: upbound-system
compositeTypeRef:
apiVersion: gcp.platformref.upbound.io/v1alpha1
kind: XCluster
mode: Pipeline
pipeline:
- step: patch-and-transform
functionRef:
name: upbound-function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
- name: XNetwork
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
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

- name: XOss
base:
apiVersion: observe.platform.upbound.io/v1alpha1
kind: XOss
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.id
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.operators.prometheus.version
toFieldPath: spec.parameters.operators.prometheus.version

- name: XFlux
base:
apiVersion: gitops.platform.upbound.io/v1alpha1
kind: XFlux
patches:
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.parameters.deletionPolicy
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.id
toFieldPath: spec.parameters.providerConfigName
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.operators.flux.version
toFieldPath: spec.parameters.operators.flux.version
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.operators.flux-sync.version
toFieldPath: spec.parameters.operators.flux-sync.version
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.gitops
toFieldPath: spec.parameters.source

- name: usageXGkeByXFlux
base:
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: Usage
spec:
by:
apiVersion: gitops.platform.upbound.io/v1alpha1
kind: XFlux
resourceSelector:
matchControllerRef: true
of:
apiVersion: gcp.platform.upbound.io/v1alpha1
kind: XGKE
resourceSelector:
matchControllerRef: true

- name: usageXGkeByXOss
base:
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: Usage
spec:
by:
apiVersion: observe.platform.upbound.io/v1alpha1
kind: XOss
resourceSelector:
matchControllerRef: true
of:
apiVersion: gcp.platform.upbound.io/v1alpha1
kind: XGKE
resourceSelector:
matchControllerRef: true

- name: usageXGkeByArbitraryLabeledRelease
base:
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: Usage
spec:
by:
apiVersion: helm.crossplane.io/v1beta1
kind: Release
resourceSelector:
matchLabels:
platform.upbound.io/deletion-ordering: enabled
of:
apiVersion: gcp.platform.upbound.io/v1alpha1
kind: XGKE
resourceSelector:
matchControllerRef: true
readinessChecks:
- type: None
Loading