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

Move variable defaults to -var-file #1079

Merged
merged 8 commits into from
Nov 21, 2022
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
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKER_BINARY ?= packer
PACKER_VARIABLES := $(shell $(PACKER_BINARY) inspect -machine-readable eks-worker-al2.json | grep 'template-variable' | awk -F ',' '{print $$4}')
AVAILABLE_PACKER_VARIABLES := $(shell $(PACKER_BINARY) inspect -machine-readable eks-worker-al2.json | grep 'template-variable' | awk -F ',' '{print $$4}')

K8S_VERSION_PARTS := $(subst ., ,$(kubernetes_version))
K8S_VERSION_MINOR := $(word 1,${K8S_VERSION_PARTS}).$(word 2,${K8S_VERSION_PARTS})
Expand Down Expand Up @@ -65,14 +65,20 @@ lint: ## Check the source files for syntax and format issues
test: ## run the test-harness
test/test-harness.sh

# include only variables which have a defined value
PACKER_VARIABLES := $(foreach packerVar,$(AVAILABLE_PACKER_VARIABLES),$(if $($(packerVar)),$(packerVar)))
PACKER_VAR_FLAGS := -var-file eks-worker-al2-variables.json \
$(if $(PACKER_VARIABLE_FILE),--var-file=$(PACKER_VARIABLE_FILE),) \
$(foreach packerVar,$(PACKER_VARIABLES),-var $(packerVar)='$($(packerVar))')

.PHONY: validate
validate: ## Validate packer config
$(PACKER_BINARY) validate $(foreach packerVar,$(PACKER_VARIABLES), $(if $($(packerVar)),--var $(packerVar)='$($(packerVar))',)) eks-worker-al2.json
$(PACKER_BINARY) validate $(PACKER_VAR_FLAGS) eks-worker-al2.json

.PHONY: k8s
k8s: validate ## Build default K8s version of EKS Optimized AL2 AMI
@echo "$(T_GREEN)Building AMI for version $(T_YELLOW)$(kubernetes_version)$(T_GREEN) on $(T_YELLOW)$(arch)$(T_RESET)"
$(PACKER_BINARY) build -timestamp-ui -color=false $(foreach packerVar,$(PACKER_VARIABLES), $(if $($(packerVar)),--var $(packerVar)='$($(packerVar))',)) eks-worker-al2.json
$(PACKER_BINARY) build -timestamp-ui -color=false $(PACKER_VAR_FLAGS) eks-worker-al2.json

# Build dates and versions taken from https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ To build an Amazon EKS Worker AMI for a particular Kubernetes version run the fo
```bash
make 1.23 ## Build a Amazon EKS Worker AMI for k8s 1.23
```

### AMI template variables

Default values for most variables are defined in [a default variable file](eks-worker-al2-variables.json).

Users have the following options for specifying their own values:

1. Provide a variable file with the `PACKER_VARIABLE_FILE` argument to `make`. Values in this file will override values in the default variable file. Your variable file does not need to include all possible variables, as it will be merged with the default variable file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be possible to write tests for these behaviors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I saw your comment stating that packer is the one which does this so no point in testing that. Contents of that comment might be good for this section too. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd err on the side of fewer impl details in this doc, but I don't feel too strongly. Can totally add if you think it's necessary

2. Pass a key-value pair for any template variable to `make`. These values will override any values specified using the first method.

**Note** that some variables (such as `arch` and `kubernetes_version`) do not have a sensible, static default, and are satisfied by the Makefile. Such variables do not appear in the default variable file, and must be overridden (if necessary) by the second method described above.

### Building against other versions of Kubernetes binaries
To build an Amazon EKS Worker AMI with other versions of Kubernetes that are not listed above run the following AWS Command
Line Interface (AWS CLI) commands to obtain values for KUBERNETES_VERSION, KUBERNETES_BUILD_DATE, PLATFORM, ARCH from S3
Expand Down
36 changes: 36 additions & 0 deletions eks-worker-al2-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"additional_yum_repos": "",
"ami_description": "EKS Kubernetes Worker AMI with AmazonLinux2 image",
"ami_regions": "",
"ami_users": "",
"associate_public_ip_address": "",
"aws_access_key_id": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_region": "us-west-2",
"aws_secret_access_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"aws_session_token": "{{env `AWS_SESSION_TOKEN`}}",
"binary_bucket_name": "amazon-eks",
"binary_bucket_region": "us-west-2",
"cache_container_images": "false",
"cni_plugin_version": "v0.8.6",
"containerd_version": "1.6.6-1.amzn2.0.2",
"creator": "{{env `USER`}}",
"docker_version": "20.10.17-1.amzn2.0.1",
"encrypted": "false",
"kernel_version": "",
"kms_key_id": "",
"launch_block_device_mappings_volume_size": "8",
"pause_container_version": "3.5",
"pull_cni_from_github": "true",
"remote_folder": "",
"runc_version": "1.1.3-1.amzn2.0.2",
"security_group_id": "",
"sonobuoy_e2e_registry": "",
"source_ami_filter_name": "amzn2-ami-minimal-hvm-*",
"source_ami_id": "",
"source_ami_owners": "137112412989",
"ssh_interface": "",
"ssh_username": "ec2-user",
"subnet_id": "",
"temporary_security_group_source_cidrs": "",
"volume_type": "gp2"
}
71 changes: 36 additions & 35 deletions eks-worker-al2.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
{
"_comment": "All template variables are enumerated here; and most variables have a default value defined in eks-worker-al2-variables.json",
"variables": {
"additional_yum_repos": "",
"ami_description": "EKS Kubernetes Worker AMI with AmazonLinux2 image",
"additional_yum_repos": null,
"ami_description": null,
"ami_name": null,
"ami_regions": "",
"ami_users": "",
"ami_regions": null,
"ami_users": null,
"arch": null,
"associate_public_ip_address": "",
"aws_access_key_id": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_region": "us-west-2",
"aws_secret_access_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"aws_session_token": "{{env `AWS_SESSION_TOKEN`}}",
"binary_bucket_name": "amazon-eks",
"binary_bucket_region": "us-west-2",
"cache_container_images": "false",
"cni_plugin_version": "v0.8.6",
"containerd_version": "1.6.6-1.amzn2.0.2",
"creator": "{{env `USER`}}",
"docker_version": "20.10.17-1.amzn2.0.1",
"encrypted": "false",
"associate_public_ip_address": null,
"aws_access_key_id": null,
"aws_region": null,
"aws_secret_access_key": null,
"aws_session_token": null,
"binary_bucket_name": null,
"binary_bucket_region": null,
"cache_container_images": null,
"cni_plugin_version": null,
"containerd_version": null,
cartermckinnon marked this conversation as resolved.
Show resolved Hide resolved
"creator": null,
"docker_version": null,
"encrypted": null,
"instance_type": null,
"kernel_version": "",
"kms_key_id": "",
"kernel_version": null,
"kms_key_id": null,
"kubernetes_build_date": null,
"kubernetes_version": null,
"launch_block_device_mappings_volume_size": "8",
"pause_container_version": "3.5",
"pull_cni_from_github": "true",
"remote_folder": "",
"runc_version": "1.1.3-1.amzn2.0.2",
"security_group_id": "",
"sonobuoy_e2e_registry": "",
"source_ami_filter_name": "amzn2-ami-minimal-hvm-*",
"source_ami_id": "",
"source_ami_owners": "137112412989",
"ssh_interface": "",
"ssh_username": "ec2-user",
"subnet_id": "",
"temporary_security_group_source_cidrs": "",
"volume_type": "gp2"
"launch_block_device_mappings_volume_size": null,
"pause_container_version": null,
"pull_cni_from_github": null,
"remote_folder": null,
"runc_version": null,
"security_group_id": null,
"sonobuoy_e2e_registry": null,
"source_ami_filter_name": null,
"source_ami_id": null,
"source_ami_owners": null,
"ssh_interface": null,
"ssh_username": null,
"subnet_id": null,
"temporary_security_group_source_cidrs": null,
"volume_type": null
},
"builders": [
{
Expand Down Expand Up @@ -223,4 +224,4 @@
}
}
]
}
}