Skip to content

Commit

Permalink
Merge pull request #24 from portefaix/feat/crossplane-exoscale
Browse files Browse the repository at this point in the history
Exoscale provider for Crossplane
  • Loading branch information
nlamirault authored Oct 3, 2022
2 parents 2094af5 + 0c4e838 commit 120d8e2
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 35 deletions.
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,25 @@ crossplane-config: guard-CLOUD guard-ACTION ## The Crossplane configuration (CLO
crossplane-infra: guard-CLOUD guard-ACTION ## Manage the components (CLOUD=xxx ACTION=xxx)
@kustomize build krm/crossplane/$(CLOUD)/infra | kubectl $(ACTION) -f -

.PHONY: crossplane-gcp-credentials
crossplane-gcp-credentials: guard-GCP_PROJECT_ID guard-GCP_SERVICE_ACCOUNT_NAME ## Generate credentials for GCP (GCP_PROJECT_ID=xxx GCP_SERVICE_ACCOUNT_NAME=xxx GCP_SERVICE_ACCOUNT_KEYFILE=xxx)
@./hack/scripts/gcp.sh $(GCP_PROJECT_ID) $(GCP_SERVICE_ACCOUNT_NAME)
.PHONY: crossplane-credentials
crossplane-credentials: guard-CLOUD ## Generate credentials for a Cloud provider (CLOUD=xxx)
@./hack/scripts/$(CLOUD).sh crossplane-$(CLOUD)-credentials crossplane-system

.PHONY: crossplane-aws-credentials
crossplane-aws-credentials: ## Generate credentials for AWS (AWS_ACCESS_KEY=xxx AWS_SECRET_ACCESS_KEY=xxx)
@./hack/scripts/aws.sh crossplane-aws-credentials crossplane-system
# .PHONY: crossplane-gcp-credentials
# crossplane-gcp-credentials: guard-GCP_PROJECT_ID guard-GCP_SERVICE_ACCOUNT_NAME ## Generate credentials for GCP (GCP_PROJECT_ID=xxx GCP_SERVICE_ACCOUNT_NAME=xxx GCP_SERVICE_ACCOUNT_KEYFILE=xxx)
# @./hack/scripts/gcp.sh crossplane-gcp-credentials crossplane-system

# .PHONY: crossplane-aws-credentials
# crossplane-aws-credentials: ## Generate credentials for AWS (AWS_ACCESS_KEY=xxx AWS_SECRET_ACCESS_KEY=xxx)
# @./hack/scripts/aws.sh crossplane-aws-credentials crossplane-system

.PHONY: crossplane-azure-credentials
crossplane-azure-credentials: guard-AZURE_SUBSCRIPTION_ID guard-AZURE_PROJECT_NAME ## Generate credentials for Azure
@./hack/scripts/azure.sh $(AZURE_SUBSCRIPTION_ID) $(AZURE_PROJECT_NAME) crossplane-azure-credentials crossplane-system

.PHONY: crossplane-scaleway-credentials
crossplane-scaleway-credentials: ## Generate credentials for Azure
@./hack/scripts/scaleway.sh crossplane-scaleway-credentials crossplane-system
# .PHONY: crossplane-scaleway-credentials
# crossplane-scaleway-credentials: ## Generate credentials for Azure
# @./hack/scripts/scaleway.sh crossplane-scaleway-credentials crossplane-system


# ====================================
Expand Down
54 changes: 54 additions & 0 deletions hack/scripts/exoscale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/env bash

# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

reset_color="\\e[0m"
color_red="\\e[31m"
color_green="\\e[32m"
color_blue="\\e[36m";

# declare -r this_dir=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
# declare -r root_dir=$(cd ${this_dir}/../.. && pwd)

function echo_fail { echo -e "${color_red}$*${reset_color}"; }
function echo_success { echo -e "${color_green}$*${reset_color}"; }
function echo_info { echo -e "${color_blue}$*${reset_color}"; }

echo_info "[Exoscale] Configure Exoscale provider"

[ -z "${EXOSCALE_API_KEY}" ] && echo_fail "Environment variable EXOSCALE_API_KEY not satisfied" && exit 1
[ -z "${EXOSCALE_API_SECRET}" ] && echo_fail "Environment variable EXOSCALE_API_SECRET not satisfied" && exit 1
SECRET_NAME=$1
NAMESPACE=$2

EXOSCALE_CREDS_ENCODED=$(cat <<EOF | base64 | tr -d "\n"
{
"key": "${EXOSCALE_API_KEY}",
"secret": "${EXOSCALE_API_SECRET}"
}
EOF
)

echo_info "[Kubernetes] Exoscale: Create secret ${SECRET_NAME} into ${NAMESPACE}"
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: ${SECRET_NAME}
namespace: ${NAMESPACE}
type: Opaque
data:
credentials: ${EXOSCALE_CREDS_ENCODED}
EOF
12 changes: 6 additions & 6 deletions hack/scripts/gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function echo_info { echo -e "${color_blue}$*${reset_color}"; }

echo_info "[GCP] Configure GCP provider"

GCP_PROJECT_ID=$1
[ -z "${GCP_PROJECT_ID}" ] && echo_fail "GCP project not satisfied" && exit 1
GCP_SERVICE_ACCOUNT_NAME=$2
[ -z "${GCP_SERVICE_ACCOUNT_NAME}" ] && echo_fail "GCP srvice account name not satisfied" && exit 1
[ -z "${GCP_PROJECT_ID}" ] && echo_fail "Environment variable GCP_PROJECT_ID not satisfied" && exit 1
[ -z "${GCP_SERVICE_ACCOUNT_NAME}" ] && echo_fail "Environment variable GCP_SERVICE_ACCOUNT_NAME not satisfied" && exit 1
SECRET_NAME=$1
NAMESPACE=$2

echo_info "[GCP] Project: ${GCP_PROJECT_ID} Service Account name: ${GCP_SERVICE_ACCOUNT_NAME}"

Expand Down Expand Up @@ -95,8 +95,8 @@ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: crossplane-gcp-credentials
namespace: crossplane-system
name: ${SECRET_NAME}
namespace: ${NAMESPACE}
type: Opaque
data:
credentials: ${GCP_CREDS_ENCODED}
Expand Down
34 changes: 14 additions & 20 deletions krm/crossplane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,30 @@

## Cloud provider credentials

* AWS
* Choose the cloud provider (`aws`, `gcp` or `azure`)

```shell
> make crossplane-aws-credentials
> export CLOUD=xxx
```

* GCP
* Setup credentials

```shell
> make crossplane-gcp-credentials GCP_PROJECT_ID=myproject-prod GCP_SERVICE_ACCOUNT_NAME=kubernetes-krm
> make crossplane-credentials
```

* Azure
For Azure:

```shell
> make crossplane-azure-credentials AZURE_SUBSCRIPTION_ID=xxxxxxx AZURE_PROJECT_NAME=xxxxxx
```

* Scaleway

```shell
> make crossplane-scaleway-credentials
```

## Crossplane Cloud Provider configuration

* Choose the cloud provider (`aws`, `gcp` or `azure`)

```shell
> export CROSSPLANE_CLOUD_PROVIDER=xxx
```

* Install Crossplane provider:

```shell
> make crossplane-provider CLOUD=${CROSSPLANE_CLOUD_PROVIDER} ACTION=apply
> make crossplane-provider ACTION=apply
```

For Scaleway, execute also:
Expand All @@ -61,11 +49,17 @@ For Scaleway, execute also:
* Setup Crossplane configuration:

```shell
❯ make crossplane-config CLOUD=${CROSSPLANE_CLOUD_PROVIDER} ACTION=apply
❯ make crossplane-config ACTION=apply
```

* Deploy infrastructure:

```shell
❯ make crossplane-infra CLOUD=${CROSSPLANE_CLOUD_PROVIDER} ACTION=apply
❯ make crossplane-infra ACTION=apply
```

* Delete infrastructure:

```shell
❯ make crossplane-infra ACTION=delete
```
22 changes: 22 additions & 0 deletions krm/crossplane/exoscale/config/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: crossplane-system
transformers:
- labels.yaml
resources:
- ./provider-config.yaml
31 changes: 31 additions & 0 deletions krm/crossplane/exoscale/config/labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: builtin
kind: LabelTransformer
metadata:
name: labels
labels:
app.kubernetes.io/name: portefaix-krm-exoscale
app.kubernetes.io/instance: portefaix-krm-exoscale-app
app.kubernetes.io/component: krm-crossplane
app.kubernetes.io/version: v0.1.0
app.kubernetes.io/part-of: portefaix-krm-exoscale
app.kubernetes.io/managed-by: kustomize
crossplane.io/version: v1.9.1
crossplane.io/provider: exoscale-v0.1.0
fieldSpecs:
- path: metadata/labels
create: true
26 changes: 26 additions & 0 deletions krm/crossplane/exoscale/config/provider-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: exoscale.jet.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: crossplane-exoscale
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: crossplane-exoscale-credentials
key: credentials
28 changes: 28 additions & 0 deletions krm/crossplane/exoscale/infra/instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: compute.exoscale.jet.crossplane.io/v1alpha1
kind: Instance
metadata:
name: portefaix-krm-bastion
spec:
forProvider:
displayName: portefaix-krm-bastion
zone: de-fra-1
diskSize: 30
template: "Linux Ubuntu 22.04 LTS 64-bit"
securityGroups: ["default"]
providerConfigRef:
name: crossplane-exoscale
24 changes: 24 additions & 0 deletions krm/crossplane/exoscale/infra/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: crossplane-system
transformers:
- labels.yaml
resources:
- ./sg.yaml
# - ./instance.yaml
- ./sks.yaml
31 changes: 31 additions & 0 deletions krm/crossplane/exoscale/infra/labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) Nicolas Lamirault <nicolas.lamirault@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: builtin
kind: LabelTransformer
metadata:
name: labels
labels:
app.kubernetes.io/name: portefaix-krm-alibaba
app.kubernetes.io/instance: portefaix-krm-alibaba-app
app.kubernetes.io/component: krm-crossplane
app.kubernetes.io/version: v0.1.0
app.kubernetes.io/part-of: portefaix-krm-alibaba
app.kubernetes.io/managed-by: kustomize
crossplane.io/version: v1.9.1
crossplane.io/provider: alibaba-v0.5.0
fieldSpecs:
- path: metadata/labels
create: true
Loading

0 comments on commit 120d8e2

Please sign in to comment.