### End-to-End Test Output Example Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/testing.md Example output from the end-to-end test script, showing cluster creation, image building, and controller installation progress. ```text 2022-07-15T19:52:55+0000 [INFO] Creating KIND cluster ... 2022-07-15T19:52:55+0000 [INFO] Creating cluster with name "ack-test-e9e83a17" 2022-07-15T19:52:55+0000 [INFO] Using configuration "kind-two-node-cluster.yaml" Creating cluster "ack-test-e9e83a17" ... ✓ Ensuring node image (kindest/node:v1.22.9) đŸ–ŧ ✓ Preparing nodes đŸ“Ļ đŸ“Ļ ✓ Writing configuration 📜 ✓ Starting control-plane đŸ•šī¸ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 ✓ Joining worker nodes 🚜 Set kubectl context to "kind-ack-test-e9e83a17" You can now use your cluster with: kubectl cluster-info --context kind-ack-test-e9e83a17 --kubeconfig /local/home/nithomso/go/src/github.com/aws-controllers-k8s/test-infra/scripts/../build/clusters/ack-test-e9e83a17/kubeconfig Not sure what to do next? 😅 Check out https://kind.sigs.k8s.io/docs/user/quick-start/ 2022-07-15T19:53:42+0000 [INFO] Exporting KUBECONFIG=/local/home/nithomso/go/src/github.com/aws-controllers-k8s/test-infra/scripts/../build/clusters/ack-test-e9e83a17/kubeconfig 2022-07-15T19:53:42+0000 [INFO] Building controller image ... WARNING! Your password will be stored unencrypted in /home/nithomso/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store [+] Building 352.7s (21/21) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 39B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for public.ecr.aws/eks-distro-build-tooling/eks-distro-minim 0.2s => [internal] load metadata for public.ecr.aws/bitnami/golang:1.17 0.5s => [auth] aws:: eks-distro-build-tooling/eks-distro-minimal-base-nonroot:pull token for 0.0s => [auth] aws:: bitnami/golang:pull token for public.ecr.aws 0.0s => [builder 1/11] FROM public.ecr.aws/bitnami/golang:1.17@sha256:386b0edb486b872c5db270 9.9s => => resolve public.ecr.aws/bitnami/golang:1.17@sha256:386b0edb486b872c5db2702c997ac364 0.0s => => sha256:386b0edb486b872c5db2702c997ac364749d5b52908ba2f8db33e67e32c 1.58kB / 1.58kB 0.0s => => sha256:6474ea435b8fd7c66546676ee6bb9fafdede6679aa57119d3b3e91c23c9 4.25kB / 4.25kB 0.0s => => sha256:e4d5dd6e67b14bf5bfc57a4ed6126d2ff9618ae17a809ba0eed98b68d 30.87MB / 30.87MB 0.5s => => sha256:163e77b4424a8a2f2433544cd177d3ab5b67cd42ff2a6332788f2569a53e076 768B / 768B 0.2s => => sha256:1f31511aab3c72a7f8227e41e7c0b2d71ba2b0bef7c18c9ae8343f9 125.13MB / 125.13MB 4.0s => => sha256:c9e9361513e51d32efbc5726aa75f2bf6a0ee5d59d5ef002f127bd1 135.04MB / 135.04MB 5.3s => => extracting sha256:e4d5dd6e67b14bf5bfc57a4ed6126d2ff9618ae17a809ba0eed98b68d62c200d 0.7s => => sha256:f6e1dc6697990041781953a87be7a91a0b0a30f436b93fc277f2a160fd41f87 258B / 258B 0.6s => => sha256:6ec6c2b2145be26a5e68b86aadf441144a44f1bba0e70b3cab1988d286814d5 124B / 124B 0.7s => => extracting sha256:163e77b4424a8a2f2433544cd177d3ab5b67cd42ff2a6332788f2569a53e0769 0.0s => => extracting sha256:1f31511aab3c72a7f8227e41e7c0b2d71ba2b0bef7c18c9ae8343f9739f78dfa 2.4s => => extracting sha256:c9e9361513e51d32efbc5726aa75f2bf6a0ee5d59d5ef002f127bd1b503582b3 2.9s => => extracting sha256:f6e1dc6697990041781953a87be7a91a0b0a30f436b93fc277f2a160fd41f87c 0.0s => => extracting sha256:6ec6c2b2145be26a5e68b86aadf441144a44f1bba0e70b3cab1988d286814d51 0.0s => CACHED [stage-1 1/3] FROM public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal- 0.0s => [internal] load build context 0.0s ``` -------------------------------- ### Copy Example Test Configuration Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/testing.md Copy the example test configuration file to customize it for your testing needs. This file resides in the root of your test-infra directory. ```bash cp test_config.example.yaml test_config.yaml ``` -------------------------------- ### Set Environment Variables for EventBridge Example Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/eventbridge-example.md Define environment variables required for the EventBridge and SQS setup. Ensure AWS_REGION and AWS_ACCOUNT_ID are correctly set. ```bash export EVENTBRIDGE_NAMESPACE=eventbridge-example export EVENTBUS_NAME=custom-eventbus-ack export RULE_NAME=custom-eventbus-ack-sqs-rule export TARGET_QUEUE=custom-eventbus-ack-rule-sqs-target ``` -------------------------------- ### Start Local Hugo Server Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/README.md Starts the Hugo development server to preview documentation changes locally. Ensure API references are generated before running. ```bash $ npm start ``` -------------------------------- ### Install Operator SDK Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/operatorhub-onboarding.md Installs the Operator SDK into the code-generator bin directory. This is a prerequisite for building controllers and generating bundles. ```shell ./scripts/install-operator-sdk.sh ``` -------------------------------- ### Install Application Auto Scaling Controller Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Install the Application Auto Scaling ACK service controller using Helm. This command also creates the necessary namespace if it doesn't exist. ```bash export ACK_K8S_NAMESPACE=ack-system helm install -n $ACK_K8S_NAMESPACE --create-namespace --skip-crds ack-$SERVICE-controller \ $CHART_EXPORT_PATH/$SERVICE-chart ``` -------------------------------- ### Example Git Push Output Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/setup.md This is an example of the output you might see after pushing your changes, including repository moved messages and instructions for creating a pull request. ```bash Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 8 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 710 bytes | 710.00 KiB/s, done. Total 4 (delta 2), reused 0 (delta 0) remote: Resolving deltas: 100% (2/2), completed with 2 local objects. remote: This repository moved. Please use the new location: remote: git@github.com:$GITHUB_ID/aws-controllers-k8s.git remote: remote: Create a pull request for 'docs' on GitHub by visiting: remote: https://github.com/$GITHUB_ID/aws-controllers-k8s/pull/new/docs remote: To github.com:a-hilaly/aws-controllers-k8s * [new branch] docs -> docs ``` -------------------------------- ### Install ACK Lambda service controller Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-with-secrets-manager.md Deploy the ACK service controller for Amazon Lambda using the lambda-chart Helm chart. This example deploys to us-west-2, but any supported region can be used. ```bash SERVICE=lambda RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') helm install --create-namespace -n ack-system oci://public.ecr.aws/aws-controllers-k8s/lambda-chart "--version=${RELEASE_VERSION}" --generate-name --set=aws.region=us-west-2 ``` -------------------------------- ### Verify Helm Chart Installation Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/install.md Lists installed Helm charts in the specified namespace to verify the ACK service controller installation. The output should include details of the deployed chart. ```bash helm list --namespace $ACK_SYSTEM_NAMESPACE -o yaml ``` -------------------------------- ### Install EC2-Controller Helm Chart Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/ec2-example.md Install the EC2-Controller using its Helm chart. This command sets the service, region, and fetches the latest release version. Ensure you replace `` with your desired AWS region. ```bash export SERVICE=ec2 export AWS_REGION= export RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') helm install --create-namespace -n ack-system oci://public.ecr.aws/aws-controllers-k8s/ec2-chart "--version=${RELEASE_VERSION}" --generate-name --set=aws.region=${AWS_REGION} ``` -------------------------------- ### Determine Script and Root Directories (Alternative) Source: https://github.com/aws-controllers-k8s/community/blob/main/scripts/BASH_STYLE_CONVENTIONS.md This example demonstrates how directory variables are determined, including a case where sourcing the script leads to different results for SCRIPTS_DIR. ```bash #!/usr/bin/env bash # test.sh THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" echo $THIS_DIR SCRIPTS_DIR=$(cd "$(dirname "$0")"; pwd) echo $SCRIPTS_DIR ``` -------------------------------- ### Define Script Arguments and Usage Source: https://github.com/aws-controllers-k8s/community/blob/main/scripts/BASH_STYLE_CONVENTIONS.md Prefer a fixed number of arguments and use environment variables for optional behavior. This example shows how to define usage instructions and validate the number of arguments. ```bash USAGE=" Usage: $(basename "$0") should be an AWS service API aliases that you wish to build -- e.g. 's3' 'sns' or 'sqs' Environment variables: CHART_INPUT_PATH: Specify a path for the Helm chart to use as input. Default: services/{SERVICE}/helm PACKAGE_OUTPUT_PATH: Specify a path for the Helm chart package to output to. Default: $BUILD_DIR/release/{SERVICE} " if [ $# -ne 1 ]; then echo "ERROR: $(basename "$0") accepts one parameter, the SERVICE" 1>&2 echo "$USAGE" exit 1 fi ``` -------------------------------- ### Install Hugo Dependencies Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/README.md Installs the necessary Node.js dependencies for the Hugo development environment. ```bash npm install ``` -------------------------------- ### Install EMR on EKS Controller using Helm Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/emr-on-eks-example.md Install the ACK EMR on EKS controller using Helm. This command logs into the public ECR registry and installs the chart from the specified OCI repository, using the fetched release version and AWS region. ```bash echo "installing ack-$SERVICE-controller" aws ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws helm install --create-namespace -n $ACK_SYSTEM_NAMESPACE ack-$SERVICE-controller \ oci://public.ecr.aws/aws-controllers-k8s/$SERVICE-chart --version=$RELEASE_VERSION --set=aws.region=$AWS_REGION ``` -------------------------------- ### Create Kubernetes Namespace and EventBus Resource Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/eventbridge-example.md Creates a Kubernetes namespace for the EventBridge example and defines a custom EventBus resource using a YAML manifest. ```bash kubectl create ns ${EVENTBRIDGE_NAMESPACE} cat < bus.yaml apiVersion: eventbridge.services.k8s.aws/v1alpha1 kind: EventBus metadata: name: ${EVENTBUS_NAME} spec: name: ${EVENTBUS_NAME} EOF kubectl -n ${EVENTBRIDGE_NAMESPACE} create -f bus.yaml ``` -------------------------------- ### Create ACK System Namespace Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/openshift.md Creates the 'ack-system' namespace if it does not already exist. This is a prerequisite for installing ACK controllers. ```bash oc new-project ack-system ``` -------------------------------- ### Field-Focused ackgenconfig Implementation Example Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/codegen-refactor/inference.md This snippet shows the proposed implementation of `GetRenames` within the `Model` struct, reflecting the move to a field-focused approach for processing `ackgenconfig` data. ```go // GetRenames returns all renames for the provided field defined in the generator config func (m *Model) GetRenames(field *Field) []string { ... return field.Renames() } ``` -------------------------------- ### Field-Focused ackgenconfig Interface Example Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/codegen-refactor/inference.md This snippet demonstrates the updated `generator.yaml` interface for defining resource configurations, shifting to a field-focused approach for clarity and ease of use. ```yaml resources: Bucket: fields: Name: #sources value from Bucket ``` -------------------------------- ### Deploy Lambda OCI Function with ACK Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-oci-example.md This example defines a Kubernetes manifest for a Lambda OCI function and deploys it using `kubectl`. Ensure your AWS credentials and IAM role for Lambda are configured. ```shell export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text) export IMAGE_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/hello-world:latest " export FUNCTION_NAME="lambda-oci-ack" export LAMBDA_ROLE="arn:aws:iam::${AWS_ACCOUNT_ID}:role/lambda_basic_execution" read -r -d '' LAMBDA_MANIFEST < function.yaml kubectl create -f function.yaml ``` -------------------------------- ### Adopt an S3 Bucket with Custom Metadata Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/adopted-resource.md Use this example to adopt an existing S3 bucket. It demonstrates overriding the default Kubernetes object metadata, including name, namespace, and labels. ```yaml apiVersion: services.k8s.aws/v1alpha1 kind: AdoptedResource metadata: name: adopt-my-existing-bucket spec: aws: nameOrID: example-bucket kubernetes: group: s3.services.k8s.aws kind: Bucket metadata: name: my-existing-bucket namespace: default labels: app: foo ``` -------------------------------- ### Build Docker Image Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-oci-example.md Builds the Docker image locally using the created Dockerfile. Ensure npm is installed to manage dependencies. ```shell npm init -y docker build -t hello-world . ``` -------------------------------- ### Install ACK Lambda Controller Helm Chart Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-oci-example.md Deploys the ACK service controller for Amazon Lambda using the lambda-chart Helm chart. Ensure you are logged into the Helm registry first. ```bash aws ecr-public get-login-password --region us-west-2 | helm registry login --username AWS --password-stdin public.ecr.aws ``` ```bash SERVICE=lambda RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') helm install --create-namespace -n ack-system oci://public.ecr.aws/aws-controllers-k8s/lambda-chart "--version=${RELEASE_VERSION}" --generate-name --set=aws.region=us-west-2 ``` -------------------------------- ### Download and Extract SageMaker Helm Chart Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/sagemaker-example.md Downloads the latest SageMaker ACK service controller Helm chart and extracts it to a local directory. This prepares the chart for customization and installation. ```bash export HELM_EXPERIMENTAL_OCI=1 export SERVICE=sagemaker export RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') if [[ -z "$RELEASE_VERSION" ]]; then RELEASE_VERSION=v1.2.0 fi export CHART_EXPORT_PATH=/tmp/chart export CHART_REF=$SERVICE-chart export CHART_REPO=public.ecr.aws/aws-controllers-k8s/$CHART_REF export CHART_PACKAGE=$CHART_REF-$RELEASE_VERSION.tgz mkdir -p $CHART_EXPORT_PATH helm pull oci://$CHART_REPO --version $RELEASE_VERSION -d $CHART_EXPORT_PATH tar xvf $CHART_EXPORT_PATH/$CHART_PACKAGE -C $CHART_EXPORT_PATH ``` -------------------------------- ### Provision RDS MariaDB Instance Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/rds-example.md This example shows how to provision an AWS RDS for MariaDB 10.6 instance by creating a DBInstance custom resource. Ensure the master password is set in a Kubernetes Secret. ```bash RDS_INSTANCE_NAME="" cat < rds-mariadb.yaml apiVersion: rds.services.k8s.aws/v1alpha1 kind: DBInstance metadata: name: "${RDS_INSTANCE_NAME}" spec: allocatedStorage: 20 dbInstanceClass: db.t4g.micro dbInstanceIdentifier: "${RDS_INSTANCE_NAME}" engine: mariadb engineVersion: "10.6" masterUsername: "admin" masterUserPassword: namespace: default name: "${RDS_INSTANCE_NAME}-password" key: password EOF kubectl apply -f rds-mariadb.yaml ``` -------------------------------- ### Verify CRD Installation Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/ec2-example.md Check if the Custom Resource Definitions (CRDs) for EC2 resources have been successfully installed on your Kubernetes cluster using `kubectl get crds`. ```bash kubectl get crds ``` -------------------------------- ### Build Controller Command and Output Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/code-generator-config.md Demonstrates the command to build a controller for a specified service (e.g., ECR) and the expected output, including directory and file structure changes after generation. ```bash [jaypipes@thelio code-generator]$ make build-controller SERVICE=ecr building ack-generate ... ok. ==== building ecr-controller ==== Copying common custom resource definitions into ecr Building Kubernetes API objects for ecr Generating deepcopy code for ecr Generating custom resource definitions for ecr Building service controller for ecr Generating RBAC manifests for ecr Running gofmt against generated code for ecr Updating additional GitHub repository maintenance files ==== building ecr-controller release artifacts ==== Building release artifacts for ecr-v0.0.0-non-release Generating common custom resource definitions Generating custom resource definitions for ecr Generating RBAC manifests for ecr ``` ```tree [jaypipes@thelio ecr-controller]$ tree apis/ config/ pkg/ apis/ └── v1alpha1 ├── ack-generate-metadata.yaml ├── doc.go ├── enums.go ├── generator.yaml ├── groupversion_info.go └── types.go config/ ├── controller │ ├── deployment.yaml │ ├── kustomization.yaml │ └── service.yaml ├── crd │ ├── common │ │ ├── bases │ │ │ ├── services.k8s.aws_adoptedresources.yaml │ │ │ └── services.k8s.aws_fieldexports.yaml │ │ └── kustomization.yaml │ └── kustomization.yaml ├── default │ └── kustomization.yaml ├── overlays │ └── namespaced │ ├── kustomization.yaml │ ├── role-binding.json │ └── role.json └── rbac ├── cluster-role-binding.yaml ├── cluster-role-controller.yaml ├── kustomization.yaml ├── role-reader.yaml ├── role-writer.yaml └── service-account.yaml pkg/ ├── resource │ └── registry.go └── version └── version.go 11 directories, 25 files ``` -------------------------------- ### Monitor Training Job Status Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/sagemaker-example.md Watch the status of the SageMaker training job using `kubectl get trainingjob.sagemaker --watch`. The status will progress through stages like Starting, Downloading, Training, and finally Completed. ```bash kubectl get trainingjob.sagemaker --watch ``` -------------------------------- ### Execute S3 Bucket Creation Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Make the `create-bucket.sh` script executable and then run it to create the S3 bucket for SageMaker. ```bash chmod +x create-bucket.sh ./create-bucket.sh ``` -------------------------------- ### Apply FieldExport CRD Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/openshift.md Manually apply the FieldExport CRD before installing any controller to prevent installation conflicts. This is required for CRDs shared across multiple ACK installations. ```bash oc apply -f https://raw.githubusercontent.com/aws-controllers-k8s/runtime/main/config/crd/bases/services.k8s.aws_fieldexports.yaml ``` -------------------------------- ### Apply AdoptedResource CRD Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/openshift.md Manually apply the AdoptedResource CRD before installing any controller to prevent installation conflicts. This is required for CRDs shared across multiple ACK installations. ```bash oc apply -f https://raw.githubusercontent.com/aws-controllers-k8s/runtime/main/config/crd/bases/services.k8s.aws_adoptedresources.yaml ``` -------------------------------- ### Create SQS Queue Manifest and Apply Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/sqs-example.md Use this command to create a namespace, define an SQS queue manifest with an inline policy, and apply it to your EKS cluster. Ensure AWS region and account ID environment variables are set. ```bash QUEUE_NAMESPACE=sqs-example QUEUE_NAME=basic-sqs kubectl create ns ${QUEUE_NAMESPACE} cat < basic-sqs-queue.yaml apiVersion: sqs.services.k8s.aws/v1alpha1 kind: Queue metadata: name: ${QUEUE_NAME} annotations: services.k8s.aws/region: ${AWS_REGION} spec: queueName: ${QUEUE_NAME} policy: | { "Statement": [{ "Sid": "__owner_statement", "Effect": "Allow", "Principal": { "AWS": "${AWS_ACCOUNT_ID}" }, "Action": "sqs:SendMessage", "Resource": "arn:aws:sqs:${AWS_REGION}:${AWS_ACCOUNT_ID}:${QUEUE_NAME}" }] } EOF kubectl -n ${QUEUE_NAMESPACE} create -f basic-sqs-queue.yaml ``` -------------------------------- ### Install ACK Service Controller with Helm Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/install.md Installs the latest version of an ACK service controller using Helm. Ensure you have Helm 3.8+ installed and have logged into the ECR public Helm registry. The `AWS_REGION` variable specifies the default region for resource creation. ```bash export SERVICE=s3 export RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') export ACK_SYSTEM_NAMESPACE=ack-system export AWS_REGION=us-west-2 aws ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws helm install --create-namespace -n $ACK_SYSTEM_NAMESPACE ack-$SERVICE-controller \ oci://public.ecr.aws/aws-controllers-k8s/$SERVICE-chart --version=$RELEASE_VERSION --set=aws.region=$AWS_REGION ``` -------------------------------- ### Apply Training Job Configuration Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/sagemaker-example.md Use `kubectl apply` to create the SageMaker training job based on the `training.yaml` file. ```bash kubectl apply -f training.yaml ``` -------------------------------- ### Run End-to-End Test Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/testing.md Provisions a Kubernetes cluster using kind, builds the ACK service controller image, and loads it into the cluster. It then installs the controller and runs e2e tests to verify resource management against AWS services. ```bash make kind-test SERVICE=$SERVICE ``` -------------------------------- ### SSH into Private Instance via Bastion Host Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/ec2-example.md These commands demonstrate how to securely copy files to and then SSH into a private instance using a bastion host. Replace placeholders with your actual key file path, DNS name, and private IP. ```bash scp -i "/path/created_key_in_console_for_region.pem" "/path/created_key_in_console_for_region.pem" ec2-user@: ssh -i "/path/created_key_in_console_for_region.pem" ec2-user@ ssh -i "created_key_in_console_for_region.pem" ec2-user@ ``` -------------------------------- ### Configure `print` for kubectl get Output Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/code-generator-config.md Use the `print` configuration to include a field in the `kubectl get` output. This generates `kubebuilder` markers for the field. ```yaml resources: ... ElasticIPAddress: ... fields: ... PublicIp: print: name: PUBLIC-IP ``` -------------------------------- ### Makefile for Controller Bootstrap Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/controller-bootstrap/controller-bootstrap.md This Makefile defines targets for building the controller-bootstrap binary, generating new controllers, updating existing ones, initializing a new controller project, and running the generation process. It sets up necessary environment variables and fetches the latest versions of ACK runtime and aws-sdk-go. ```makefile SHELL := /bin/bash # Use bash syntax # Set up variables GO111MODULE=on AWS_SERVICE=$(shell echo $(SERVICE)) SERVICE_MODEL_NAME=$(shell echo $(MODEL_NAME)) ifeq ($(MODEL_NAME),) MODEL_NAME:="" endif GO_CMD_FLAGS=-tags codegen CONTROLLER_BOOTSTRAP=./bin/controller-bootstrap ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) CODE_GEN_DIR=${ROOT_DIR}/../code-generator CONTROLLER_DIR=${ROOT_DIR}/../${AWS_SERVICE}-controller AWS_SDK_GO_VERSION=$(shell curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/aws/aws-sdk-go/releases/latest | jq -r '.tag_name') ACK_RUNTIME_VERSION=$(shell curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/aws-controllers-k8s/runtime/releases/latest | jq -r '.tag_name') .DEFAULT_GOAL=run EXISTING_CONTROLLER="true" DRY_RUN="false" build: @go build ${GO_CMD_FLAGS} -o ${CONTROLLER_BOOTSTRAP} ./cmd/controller-bootstrap/. generate: build @${CONTROLLER_BOOTSTRAP} generate -s ${AWS_SERVICE} -r ${ACK_RUNTIME_VERSION} -v ${AWS_SDK_GO_VERSION} -d=${DRY_RUN} -o ${ROOT_DIR}/../${AWS_SERVICE}-controller -m ${SERVICE_MODEL_NAME} update: build @${CONTROLLER_BOOTSTRAP} generate -s ${AWS_SERVICE} -r ${ACK_RUNTIME_VERSION} -v ${AWS_SDK_GO_VERSION} -d=${DRY_RUN} -e=${EXISTING_CONTROLLER} -o ${ROOT_DIR}/../${AWS_SERVICE}-controller -m ${SERVICE_MODEL_NAME} init: generate @export SERVICE=${AWS_SERVICE} @echo "build controller attempt #1" @cd ${CODE_GEN_DIR} && make -i build-controller >/dev/null 2>/dev/null @echo "missing go.sum entry, running go mod tidy" @cd ${CONTROLLER_DIR} && go mod tidy @echo "build controller attempt #2" @cd ${CODE_GEN_DIR} && make -i build-controller >/dev/null 2>/dev/null @echo "go.sum outdated, running go mod tidy" @cd ${CONTROLLER_DIR} && go mod tidy @echo "final build controller attempt" @cd ${CODE_GEN_DIR} && make build-controller @echo "look inside ${AWS_SERVICE}-controller/generator.yaml for further instructions" run: @if [ -f ${CONTROLLER_DIR}/cmd/controller/main.go ]; then \ make update; \ else \ make init; \ fi clean: @cd ${CONTROLLER_DIR} @rm -rf ${CONTROLLER_DIR}/..?* ${CONTROLLER_DIR}/.[!.]* ${CONTROLLER_DIR}/* ``` -------------------------------- ### Restore DBInstance from Snapshot Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/rds-example.md Create a DBInstance by restoring from an existing RDS DB snapshot. Configure instance class, engine, and other parameters as needed. ```bash RDS_INSTANCE_NAME="" RDS_DB_SNAPSHOT_IDENTIFIER="" cat < rds-restore-dbinstance-snapshot.yaml apiVersion: rds.services.k8s.aws/v1alpha1 kind: DBInstance metadata: name: "${RDS_INSTANCE_NAME}" spec: allocatedStorage: 20 dbInstanceClass: db.m5.large dbInstanceIdentifier: "${RDS_INSTANCE_NAME}" engine: postgres engineVersion: "14" masterUsername: "postgres" multiAZ: true dbSnapshotIdentifier: "${RDS_DB_SNAPSHOT_IDENTIFIER}" EOF kubectl apply -f rds-restore-dbinstance-snapshot.yaml ``` -------------------------------- ### Install ACK MemoryDB Controller Helm Chart Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/memorydb-example.md Install the ACK service controller for Amazon MemoryDB using the memorydb-chart Helm chart. Specify the AWS Region for MemoryDB API calls. ```bash helm install --create-namespace -n ack-system oci://public.ecr.aws/aws-controllers-k8s/memorydb-chart --version=1.0.0 --generate-name --set=aws.region=us-east-1 ``` -------------------------------- ### Create VPC using YAML and kubectl Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/ec2-example.md Define and apply a VPC resource using a YAML manifest. Ensure the VPC is created before proceeding to create dependent resources. ```yaml cat < vpc.yaml apiVersion: ec2.services.k8s.aws/v1alpha1 kind: VPC metadata: name: vpc-tutorial-test spec: cidrBlocks: - 10.0.0.0/16 enableDNSSupport: true enableDNSHostnames: true EOF kubectl apply -f vpc.yaml ``` -------------------------------- ### Apply SageMaker Deployment YAML Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Apply the generated `deploy.yaml` file to create the SageMaker model, endpoint configuration, and endpoint using kubectl. ```bash kubectl apply -f deploy.yaml ``` -------------------------------- ### Export Environment Variables for EKS Cluster Setup Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/emr-on-eks-example.md Export necessary environment variables for EMR on EKS cluster setup, including AWS Account ID, EKS Cluster Name, and AWS Region. ```bash export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text) export EKS_CLUSTER_NAME="ack-emr-eks" export AWS_REGION="us-west-2" ``` -------------------------------- ### Create DBSubnetGroup and SecurityGroup for Aurora Serverless v2 Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/aurora-serverless-v2.md Before creating the database, set up a DBSubnetGroup and a SecurityGroup for the VPC. This involves using AWS CLI commands to retrieve VPC information and then applying a Kubernetes manifest for the DBSubnetGroup. ```bash APP_NAMESPACE=mydb kubectl create ns "${APP_NAMESPACE}" EKS_VPC_ID=$(aws eks describe-cluster --name "${EKS_CLUSTER_NAME}" --query "cluster.resourcesVpcConfig.vpcId" --output text) RDS_SUBNET_GROUP_NAME="my-subnet-group" RDS_SUBNET_GROUP_DESCRIPTION="database subnet group" EKS_SUBNET_IDS=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=${EKS_VPC_ID}" --query 'Subnets[?MapPublicIpOnLaunch==`false`].SubnetId' --output text) cat <<-EOF > db-subnet-groups.yaml apiVersion: rds.services.k8s.aws/v1alpha1 kind: DBSubnetGroup metadata: name: ${RDS_SUBNET_GROUP_NAME} namespace: ${APP_NAMESPACE} spec: name: ${RDS_SUBNET_GROUP_NAME} description: ${RDS_SUBNET_GROUP_DESCRIPTION} subnetIDs: $(printf " - %s\n" ${EKS_SUBNET_IDS}) tags: [] EOF kubectl apply -f db-subnet-groups.yaml RDS_SECURITY_GROUP_NAME="ack-security-group" RDS_SECURITY_GROUP_DESCRIPTION="ACK security group" EKS_CIDR_RANGE=$(aws ec2 describe-vpcs \ --vpc-ids "${EKS_VPC_ID}" \ --query "Vpcs[].CidrBlock" \ --output text ) RDS_SECURITY_GROUP_ID=$(aws ec2 create-security-group \ --group-name "${RDS_SECURITY_GROUP_NAME}" \ --description "${RDS_SECURITY_GROUP_DESCRIPTION}" \ --vpc-id "${EKS_VPC_ID}" \ --output text ) aws ec2 authorize-security-group-ingress \ --group-id "${RDS_SECURITY_GROUP_ID}" \ --protocol tcp \ --port 5432 \ --cidr "${EKS_CIDR_RANGE}" ``` -------------------------------- ### Export Environment Variables for EMR on EKS Controller Installation Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/emr-on-eks-example.md Export necessary environment variables before installing the EMR on EKS controller. This includes setting the service name, fetching the latest release version, and defining the ACK system namespace. ```bash export SERVICE=emrcontainers export RELEASE_VERSION=$(curl -sL https://api.github.com/repos/aws-controllers-k8s/${SERVICE}-controller/releases/latest | jq -r '.tag_name | ltrimstr("v")') export ACK_SYSTEM_NAMESPACE=ack-system ``` -------------------------------- ### Lambda Function Output Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-with-secrets-manager.md Example output from invoking the Lambda function, indicating successful secret retrieval. ```json {"statusCode":200,"body":"\"Successfully retrieved secret!\""} ``` -------------------------------- ### Download and Upload Model Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Download a pretrained XGBoost model from a GitHub repository and upload it to the created S3 bucket. ```bash wget https://github.com/aws/amazon-sagemaker-examples/raw/af6667bd0be3c9cdec23fecda7f0be6d0e3fa3ea/sagemaker_model_monitor/introduction/model/xgb-churn-prediction-model.tar.gz aws s3 cp xgb-churn-prediction-model.tar.gz s3://$SAGEMAKER_BUCKET ``` -------------------------------- ### Build Controller and Generate OLM Bundle Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/operatorhub-onboarding.md Builds the controller and generates the OLM bundle, including the ClusterServiceVersion (CSV). Ensure the ACK_GENERATE_OLM environment variable is set to true and the SERVICE variable is set to the target controller. ```shell export SERVICE=s3 ACK_GENERATE_OLM=true make build-controller SERVICE=$SERVICE ``` -------------------------------- ### APIGatewayv2 Resource Deletion Output Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/apigatewayv2-reference-example.md This is an example of the expected output after successfully deleting APIGatewayv2 resources using kubectl. ```bash api.apigatewayv2.services.k8s.aws "ack-api" deleted integration.apigatewayv2.services.k8s.aws "ack-integration" deleted route.apigatewayv2.services.k8s.aws "ack-route" deleted stage.apigatewayv2.services.k8s.aws "ack-stage" deleted ``` -------------------------------- ### Create an S3 Bucket Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/resource-crud.md This snippet shows how to create an S3 bucket using an ACK resource manifest. It first sets environment variables for the AWS account ID and bucket name, then defines the bucket manifest, saves it to a file, and applies it using kubectl. ```bash export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text) export BUCKET_NAME=my-ack-s3-bucket-$AWS_ACCOUNT_ID read -r -d '' BUCKET_MANIFEST < bucket.yaml kubectl create -f bucket.yaml kubectl describe bucket/$BUCKET_NAME ``` -------------------------------- ### Get IAM Role ARN Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Retrieve and display the ARN of the created IAM role for use in subsequent configurations. ```bash export IAM_ROLE_ARN_FOR_IRSA=$(aws --region $SERVICE_REGION iam get-role --role-name $OIDC_ROLE_NAME --output text --query 'Role.Arn') echo $IAM_ROLE_ARN_FOR_IRSA ``` -------------------------------- ### Log into Helm Registry Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/apigatewayv2-reference-example.md Log into the Helm registry to access ACK charts. Ensure you have the AWS CLI installed and configured. ```bash aws ecr-public get-login-password --region us-east-1 | helm registry login --username AWS --password-stdin public.ecr.aws ``` -------------------------------- ### Backward Compatible Integration Manifest Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/resource-reference/resource-reference.md An example of an ACK resource manifest that maintains backward compatibility by directly specifying the API identifier. ```yaml apiVersion: apigatewayv2.services.k8s.aws/v1alpha1 kind: Integration metadata: name: my-integration spec: apiID: my-api-id integrationType: HTTP_PROXY integrationURI: https://example.org integrationMethod: GET payloadFormatVersion: "1.0" ``` -------------------------------- ### LateInitialize Method with Hooks Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/late-initialization/late-initialization.md This pseudo code outlines the `LateInitialize` method in `AWSResourceManager`. It includes placeholders for pre and post read-one hooks and describes the logic for handling server-side defaults for fields specified in `LateInitializationConfig`. ```go // manager.go.tpl func (rm *resourceManager) LateInitialize( ctx context.Context, latest acktypes.AWSResource, ) (acktypes.AWSResource, error) { {{- if $hookCode := Hook .CRD "late_initialize_pre_read_one" }} {{ $hookCode }} {{- end }} // 1. Filter all the fields which have LateInitializationConfig. // 2. If there are no field needing late initialization, return `latest, nil` // 3. DeepCopy `latest` object into `latestWithDefaults` // 4. Perform ReadOne operation and set late initialized fields in `latestWithDefaults` with nil checks // 5. Collect the lateInitialized fields which are still not set in `latestWithDefault` into // `uninitializedFieldNames` slice. // 6. If `uninitializedFieldNames` is not empty // 6.a. Using `services.k8s.aws/late-initialization-attempt` annotation, calculate the // maximum delay needed for requeue amongst the `uninitializedFieldNames` // 6.b. Update the `LateInitialized` condition and `services.k8s.aws/late-initialization-attempt` annotation // in latestWithDefaults object // 6.c. return latestWithDefaults, requeueNeededAfter(max-delay-from-6a) // else // Update `LateInitialized` condition to true, remove `services.k8s.aws/late-initialization-attempt` annotation {{- if $hookCode := Hook .CRD "late_initialize_post_read_one" }} {{ $hookCode }} {{- end }} // return latestWithDefaults, nil } ``` -------------------------------- ### Get MemoryDB Cluster Port Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/memorydb-example.md Use this command to retrieve the connection port of your MemoryDB cluster. Ensure the MEMORYDB_CLUSTER_NAME variable is set. ```bash kubectl get cluster "${MEMORYDB_CLUSTER_NAME}" -o jsonpath='{.status.clusterEndpoint.port}' ``` -------------------------------- ### Clone and Configure ACK Repositories Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/setup.md Automates cloning of common ACK repositories and service controllers, setting up 'upstream' Git remotes, and fetching all branches. Requires setting your GitHub username and optionally a repository prefix. ```bash GITHUB_ID="your GH username" # Set this to "" if you did NOT take my advice above in the tip about prefixing # your personal forked ACK repository names with "ack-" ACK_REPO_PREFIX="ack-" # Clone all the common ACK repositories... COMMON="runtime code-generator test-infra" for REPO in $COMMON; do cd $GOPATH/src/github.com/aws-controllers-k8s git clone git@github.com:$GITHUB_ID/$ACK_REPO_PREFIX$REPO $REPO cd $REPO git remote add upstream git@github.com:aws-controllers-k8s/$REPO git fetch --all done # Now clone all the service controller repositories... # Change this to the list of services you forked service controllers for... SERVICES="s3 sns ecr" for SERVICE in $SERVICES; do cd $GOPATH/src/github.com/aws-controllers-k8s git clone git@github.com:$GITHUB_ID/$ACK_REPO_PREFIX$SERVICE-controller $SERVICE-controller cd $SERVICE-controller git remote add upstream git@github.com:aws-controllers-k8s/$SERVICE-controller git fetch --all done ``` -------------------------------- ### Get OIDC Information Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Retrieve the AWS Account ID and OIDC Provider URL for use in IAM role trust relationships. ```bash export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text) export OIDC_PROVIDER_URL=$(aws eks describe-cluster --name $CLUSTER_NAME --region $SERVICE_REGION \ --query "cluster.identity.oidc.issuer" --output text | cut -c9-) ``` -------------------------------- ### Get MemoryDB Cluster Endpoint Address Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/memorydb-example.md Use this command to retrieve the connection address of your MemoryDB cluster. Ensure the MEMORYDB_CLUSTER_NAME variable is set. ```bash kubectl get cluster "${MEMORYDB_CLUSTER_NAME}" -o jsonpath='{.status.clusterEndpoint.address}' ``` -------------------------------- ### Install APIGatewayv2 ACK Controller Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/apigatewayv2-reference-example.md Deploy the ACK service controller for Amazon APIGatewayv2 using the Helm chart. Specify the namespace and AWS region. ```bash helm install --create-namespace -n ack-system oci://public.ecr.aws/aws-controllers-k8s/apigatewayv2-chart --version=0.0.17 --generate-name --set=aws.region=us-east-1 ``` -------------------------------- ### Describe Scalable Target Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/autoscaling-example.md Verify the creation of the `ScalableTarget` resource by using the `kubectl describe` command. ```bash kubectl describe scalabletarget.applicationautoscaling ``` -------------------------------- ### Create Dockerfile for Lambda Function Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-oci-example.md Defines the Dockerfile to build the OCI image for the Lambda function. It uses a Node.js base image and installs dependencies. ```dockerfile FROM public.ecr.aws/lambda/nodejs:14 COPY app.js package.json ./ RUN npm install CMD [ "app.handler" ] ``` -------------------------------- ### Create Source and Target SQS Queues Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/pipes-example.md Use the AWS CLI to create the source and target SQS queues for the pipe. Ensure environment variables are set. ```bash aws sqs create-queue --queue-name ${SOURCE_QUEUE} aws sqs create-queue --queue-name ${TARGET_QUEUE} ``` -------------------------------- ### Scale ACK Controller Replicas Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/user-docs/leader-election.md Adjust the `deployment.replicas` configuration in `values.yaml` to scale the number of controller instances. For example, set it to 3 for three replicas. ```yaml deployment: replicas: 3 ``` -------------------------------- ### Set Service Environment Variable Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/contributor-docs/building-controller.md Sets the SERVICE environment variable to specify which AWS service controller to build. For example, 's3' for the S3 service. ```bash export SERVICE=s3 ``` -------------------------------- ### setResourceForContainer API Example Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/design/proposals/codegen-refactor/generator.md This Go code snippet represents the general use case API, setResourceForContainer, within the 'code' package. Unlike SetResourceForStruct, this API is not generally exposed, forcing clients to understand internal implementation details. ```go func setResourceForContainer(..., obj interface{}) error { ... } ``` -------------------------------- ### Get Lambda Function Details Source: https://github.com/aws-controllers-k8s/community/blob/main/docs/content/docs/tutorials/lambda-oci-example.md Use `kubectl describe` to retrieve detailed information about the deployed Lambda OCI function within your Kubernetes cluster. ```bash kubectl describe "function/${FUNCTION_NAME}" ```