Skip to content
Permalink
Browse files

Add automation examples for v1alpha2 clusters

Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information...
vincepri committed Aug 20, 2019
1 parent 398d4f1 commit dece5a848fe387a09b08dfdffdd6f3f6aac345f6
@@ -45,6 +45,7 @@ kubeconfig
.idea

# Ignore output manifests
examples/out
examples/_out
examples/provider-components-base.yaml
examples/provider-components/provider-components-*.yaml
config/samples
@@ -49,9 +49,6 @@ ifndef BAZEL_VERSION
https://docs.bazel.build/versions/master/install.html")
endif

# Set B64_CREDENTIALS to set an actual value in a secret
B64_CREDENTIALS ?= CREDENTIALS

# Allow overriding manifest generation destination directory
MANIFEST_ROOT ?= config
CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
@@ -98,7 +95,6 @@ docker-build: generate lint-full ## Build the docker image for controller-manage
docker build --pull . -t $(MANAGER_IMAGE)
# TODO: sed probably needs to be gnu sed not bsd sed
sed -i '' -e 's@image: .*@image: '"${MANAGER_IMAGE}"'@' ./config/default/manager_image_patch.yaml
sed -i '' -e 's@credentials: .*@credentials: '"${B64_CREDENTIALS}"'@' ./config/default/aws_credentials_patch.yaml

.PHONY: docker-push
docker-push: docker-build ## Push the docker image
@@ -154,6 +150,10 @@ generate-kubebuilder-code: ## Runs controller-gen
paths=./api/... \
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-examples
generate-examples: clean-examples ## Generate examples configurations to run a cluster.
./examples/generate.sh

## --------------------------------------
## Linting
## --------------------------------------
@@ -207,19 +207,21 @@ create-cluster: binaries ## Create a development Kubernetes cluster on AWS using
bin/clusterctl create cluster -v 4 \
--provider aws \
--bootstrap-type kind \
-m ./examples/out/machines.yaml \
-c ./examples/out/cluster.yaml \
-p ./examples/out/provider-components.yaml \
-a ./examples/out/addons.yaml
-m ./examples/_out/controlplane.yaml \
-c ./examples/_out/cluster.yaml \
-p ./examples/_out/provider-components.yaml \
-a ./examples/addons.yaml


# TODO(vincepri): Add an example to make this target work.
.PHONY: create-cluster-ha
create-cluster-ha: binaries ## Create a development Kubernetes cluster on AWS using HA examples
bin/clusterctl create cluster -v 4 \
--provider aws \
--bootstrap-type kind \
-m ./examples/machines-ha.yaml \
-c ./examples/cluster.yaml \
-p ./examples/provider-components.yaml \
-m ./examples/_out/controlplane-ha.yaml \
-c ./examples/_out/cluster.yaml \
-p ./examples/_out/provider-components.yaml \
-a ./examples/addons.yaml

.PHONY: create-cluster-management
@@ -228,28 +230,29 @@ create-cluster-management: ## Create a development Kubernetes cluster on AWS in
# Apply provider-components.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f examples/out/provider-components.yaml
create -f examples/_out/provider-components.yaml
# Create Cluster.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f examples/out/cluster.yaml
create -f examples/_out/cluster.yaml
# Create control plane machine.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f examples/out/controlplane-machine.yaml
create -f examples/_out/controlplane.yaml
# Get KubeConfig using clusterctl.
bin/clusterctl alpha phases get-kubeconfig -v=3 \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
--provider=aws \
--namespace=default \
--cluster-name=test1
# Apply addons on the target cluster, waiting for the control-plane to become available.
bin/clusterctl alpha phases apply-addons -v=3 \
--kubeconfig=./kubeconfig \
-a examples/out/addons.yaml
-a examples/addons.yaml
# Create a worker node with MachineDeployment.
kubectl \
--kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
create -f examples/out/machine-deployment.yaml
# TODO(vincepri): Fix the following example when we have a MachineDeployment.
# kubectl \
# --kubeconfig=$$(kind get kubeconfig-path --name="clusterapi") \
# create -f examples/_out/machine-deployment.yaml

.PHONY: delete-cluster
delete-cluster: binaries ## Deletes the development Kubernetes Cluster "test1"
@@ -289,8 +292,11 @@ clean-temporary: ## Remove all temporary files and folders
rm -f minikube.kubeconfig
rm -f kubeconfig
rm -rf out/
rm -rf examples/out/
rm -f examples/provider-components-base.yaml

.PHONY: clean-examples
clean-examples: ## Remove all the temporary files generated in the examples folder
rm -rf examples/_out/
rm -f examples/provider-components/provider-components-*.yaml

.PHONY: verify
verify: ## Runs verification scripts to ensure correct execution
@@ -34,20 +34,6 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/sts"
)

// KubernetesAWSSecret is the template to generate an encoded version of the
// users' AWS credentials
// nolint
const KubernetesAWSSecret = `---
apiVersion: v1
kind: Secret
metadata:
name: manager-bootstrap-credentials
namespace: aws-provider-system
type: Opaque
data:
credentials: {{ .CredentialsFile }}
`

// AWSCredentialsTemplate generates an AWS credentials file that can
// be loaded by the various SDKs.
const AWSCredentialsTemplate = `[default]
@@ -311,10 +297,6 @@ type awsCredential struct {
Region string
}

type awsCredentialsFile struct {
CredentialsFile string
}

func getEnv(key string) (string, error) {
val, ok := os.LookupEnv(key)
if !ok {
@@ -339,32 +321,12 @@ func renderAWSDefaultProfile(creds awsCredential) (*bytes.Buffer, error) {
}

func generateAWSKubernetesSecret(creds awsCredential) error {

profile, err := renderAWSDefaultProfile(creds)

if err != nil {
return err
}

encCreds := base64.StdEncoding.EncodeToString(profile.Bytes())

credsFile := awsCredentialsFile{
CredentialsFile: encCreds,
}

secretTmpl, err := template.New("AWS Credentials Secret").Parse(KubernetesAWSSecret)
if err != nil {
return err
}
var out bytes.Buffer

err = secretTmpl.Execute(&out, credsFile)

if err != nil {
return err
}

fmt.Println(out.String())

fmt.Println(encCreds)
return nil
}
@@ -7,7 +7,7 @@ resources:
- bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patches:
# patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_awsmachines.yaml

This file was deleted.

@@ -12,7 +12,7 @@ namePrefix: capa-
#commonLabels:
# someName: someValue

bases:
resources:
- ../crd
- ../rbac
- ../manager
@@ -27,7 +27,7 @@ patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# Only one of manager_auth_proxy_patch.yaml and
# manager_prometheus_metrics_patch.yaml should be enabled.
- manager_auth_proxy_patch.yaml
# - manager_auth_proxy_patch.yaml
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, uncomment the following line and
# comment manager_auth_proxy_patch.yaml.
@@ -5,4 +5,4 @@ metadata:
namespace: system
type: Opaque
data:
credentials: W2RlZmF1bHRdCmF3c19hY2Nlc3Nfa2V5X2lkID0gYWJjCmF3c19zZWNyZXRfYWNjZXNzX2tleSA9IGFiYwpyZWdpb24gPSB1cy13ZXN0LTIKCg==
credentials: ${AWS_B64ENCODED_CREDENTIALS}

0 comments on commit dece5a8

Please sign in to comment.
You can’t perform that action at this time.