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

allow kubeadm image repo customization #26

Merged
merged 3 commits into from
Aug 27, 2019
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
26 changes: 14 additions & 12 deletions images/capi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
all: build

# A list of the supported distribution/version combinations. Each member
# of BUILD_NAMES must have a corresponding file "config/BUILD_NAME.json".
BUILD_NAMES ?= ova-centos-7 ova-ubuntu-1804 ami-default
# of *_BUILD_NAMES must have a corresponding file "config/*_BUILD_NAME.json".
OVA_BUILD_NAMES ?= ova-centos-7 ova-ubuntu-1804
AMI_BUILD_NAMES ?= ami-default

# The version of Kubernetes to install.
KUBE_JSON ?= packer/config/kubernetes.json packer/config/cni.json packer/config/containerd.json
Expand All @@ -30,20 +31,21 @@ OLD_PACKER_FLAGS := $(PACKER_FLAGS)
PACKER_FLAGS := $(foreach f,$(abspath $(PACKER_VAR_FILES)),-var-file="$(f)" )
PACKER_FLAGS += $(OLD_PACKER_FLAGS)

BUILD_TARGETS := $(addprefix build-,$(BUILD_NAMES))
$(BUILD_TARGETS):
if [[ $@ = build-ova* ]] ; then \
packer build $(PACKER_FLAGS) -var-file="$(abspath packer/ova/$(subst build-,,$@).json)" packer/ova/packer.json; \
else \
packer build $(PACKER_FLAGS) -var-file="$(abspath packer/ami/$(subst build-,,$@).json)" packer/ami/packer.json; \
fi
.PHONY: $(BUILD_TARGETS)
OVA_BUILD_TARGETS := $(addprefix build-,$(OVA_BUILD_NAMES))
AMI_BUILD_TARGETS := $(addprefix build-,$(AMI_BUILD_NAMES))
$(OVA_BUILD_TARGETS):
packer build $(PACKER_FLAGS) -var-file="$(abspath packer/ova/$(subst build-,,$@).json)" packer/ova/packer.json
.PHONY: $(OVA_BUILD_TARGETS)

CLEAN_TARGETS := $(addprefix clean-,$(BUILD_NAMES))
$(AMI_BUILD_TARGETS):
packer build $(PACKER_FLAGS) -var-file="$(abspath packer/ami/$(subst build-,,$@).json)" packer/ami/packer.json
.PHONY: $(AMI_BUILD_TARGETS)

CLEAN_TARGETS := $(addprefix clean-,$(OVA_BUILD_NAMES)) $(addprefix clean-,$(AMI_BUILD_NAMES))
$(CLEAN_TARGETS):
rm -fr output/$(subst clean-,,$@)*
.PHONY: $(CLEAN_TARGETS)

build: $(BUILD_TARGETS)
build: $(OVA_BUILD_TARGETS) $(AMI_BUILD_TARGETS)
clean: $(CLEAN_TARGETS)
.PHONY: build clean
9 changes: 8 additions & 1 deletion images/capi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ The `packer/config` directory includes several JSON files that define the config
| `packer/config/kubernetes.json` | The version of Kubernetes to install |
| `packer/config/cni.json` | The version of Kubernetes CNI to install |
| `packer/config/containerd.json` | The version of containerd to install |


## Kubernetes versions
| Tested Kubernetes Versions |
|---------|
| `1.13.x` |
| `1.14.x` |
| `1.15.x` |

## Output

The OVA images are built and located in `output/BUILD_NAME+kube-KUBERNETES_VERSION`
45 changes: 0 additions & 45 deletions images/capi/ansible/filter_plugins/kube.py

This file was deleted.

8 changes: 4 additions & 4 deletions images/capi/ansible/roles/kubernetes/tasks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
name: "{{ packages }}"
vars:
packages:
- "kubelet={{ kubernetes_version | kube_platform_version('debian') }}"
- "kubeadm={{ kubernetes_version | kube_platform_version('debian') }}"
- "kubectl={{ kubernetes_version | kube_platform_version('debian') }}"
- "kubernetes-cni={{kubernetes_cni_version | kube_platform_version('debian') }}"
- "kubelet={{ kubernetes_deb_version }}"
- "kubeadm={{ kubernetes_deb_version }}"
- "kubectl={{ kubernetes_deb_version }}"
- "kubernetes-cni={{kubernetes_cni_deb_version }}"
18 changes: 14 additions & 4 deletions images/capi/ansible/roles/kubernetes/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.
---
- import_tasks: debian.yml
when: kubernetes_source == "pkg" and ansible_os_family == "Debian"
when: kubernetes_source_type == "pkg" and ansible_os_family == "Debian"

- import_tasks: redhat.yml
when: kubernetes_source == "pkg" and ansible_os_family == "RedHat"
when: kubernetes_source_type == "pkg" and ansible_os_family == "RedHat"

- import_tasks: url.yml
when: kubernetes_source != "pkg" and kubernetes_cni_source != "pkg"
when: kubernetes_source_type != "pkg" and kubernetes_cni_source_type != "pkg"

- name: Ensure that the kubelet is running
service:
Expand All @@ -31,5 +31,15 @@
dest: /etc/kubernetes-version
src: etc/kubernetes-version

- name: Create kubeadm config file
template:
dest: /etc/kubeadm.yml
src: etc/kubeadm.yml
figo marked this conversation as resolved.
Show resolved Hide resolved

- name: Kubeadm pull images
shell: 'kubeadm config images pull --cri-socket="/var/run/containerd/containerd.sock" --kubernetes-version="{{ kubernetes_semver }}"'
shell: 'kubeadm config images pull --config /etc/kubeadm.yml'

- name: delete kubeadm config
file:
path: /etc/kubeadm.yml
state: absent
8 changes: 4 additions & 4 deletions images/capi/ansible/roles/kubernetes/tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
lock_timeout: 60
vars:
packages:
- "kubelet-{{ kubernetes_version | kube_platform_version('redhat') }}"
- "kubeadm-{{ kubernetes_version | kube_platform_version('redhat') }}"
- "kubectl-{{ kubernetes_version | kube_platform_version('redhat') }}"
- "kubernetes-cni-{{kubernetes_cni_version | kube_platform_version('redhat')}}"
- "kubelet-{{ kubernetes_rpm_version }}"
- "kubeadm-{{ kubernetes_rpm_version }}"
- "kubectl-{{ kubernetes_rpm_version }}"
- "kubernetes-cni-{{kubernetes_cni_rpm_version }}"
12 changes: 6 additions & 6 deletions images/capi/ansible/roles/kubernetes/tasks/url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

- name: Download CNI tarball
get_url:
url: "{{ kubernetes_cni_source }}/{{ kubernetes_cni_semver }}/cni-plugins-{{ kubernetes_goarch }}-{{ kubernetes_cni_semver }}.tgz"
checksum: "sha1:{{ kubernetes_cni_source }}/{{ kubernetes_cni_semver }}/cni-plugins-{{ kubernetes_goarch }}-{{ kubernetes_cni_semver }}.tgz.sha1"
url: "{{ kubernetes_cni_http_source }}/{{ kubernetes_cni_semver }}/cni-plugins-{{ kubernetes_goarch }}-{{ kubernetes_cni_semver }}.tgz"
checksum: "sha1:{{ kubernetes_cni_http_source }}/{{ kubernetes_cni_semver }}/cni-plugins-{{ kubernetes_goarch }}-{{ kubernetes_cni_semver }}.tgz.sha1"
dest: /tmp/cni.tar.gz
mode: 0755
owner: root
Expand All @@ -52,11 +52,11 @@

- name: Download Kubernetes binaries
get_url:
url: "{{ kubernetes_source }}/bin/linux/{{ kubernetes_goarch }}/{{ item }}"
url: "{{ kubernetes_http_source }}/{{ kubernetes_semver }}/bin/linux/{{ kubernetes_goarch }}/{{ item }}"
# TODO(akutz) Write a script to separately download the checksum
# and verify the associated file using the correct
# checksum file format
#checksum: "sha1:{{ kubernetes_source }}/bin/linux/amd64/{{ item }}.sha1"
#checksum: "sha1:{{ kubernetes_http_source }}/bin/linux/amd64/{{ item }}.sha1"
dest: "/usr/bin/{{ item }}"
mode: 0755
owner: root
Expand All @@ -65,11 +65,11 @@

- name: Download Kubernetes images
get_url:
url: "{{ kubernetes_source }}/bin/linux/{{ kubernetes_goarch }}/{{ item }}"
url: "{{ kubernetes_http_source }}/{{ kubernetes_semver }}/bin/linux/{{ kubernetes_goarch }}/{{ item }}"
# TODO(akutz) Write a script to separately download the checksum
# and verify the associated file using the correct
# checksum file format
#checksum: "sha1:{{ kubernetes_source }}/bin/linux/amd64/{{ item }}.sha1"
#checksum: "sha1:{{ kubernetes_http_source }}/bin/linux/amd64/{{ item }}.sha1"
dest: "/tmp/{{ item }}"
loop: "{{ kubernetes_imgs }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
imageRepository: {{ kubernetes_container_registry }}
kubernetesVersion: {{ kubernetes_semver }}
---
apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
nodeRegistration:
criSocket: "/var/run/containerd/containerd.sock"
14 changes: 5 additions & 9 deletions images/capi/hack/image-build-ova.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ def main():
'ARTIFACT_ID': build['artifact_id'],
'BUILD_TIMESTAMP': build_data['build_timestamp'],
'CAPI_VERSION': build_data['capi_version'],
'CAPV_VERSION': build_data['capv_version'],
'CNI_VERSION': build_data['cni_version'],
'CNI_VERSION': build_data['kubernetes_cni_semver'],
'OS_NAME': build_data['os_name'],
'ISO_CHECKSUM': build_data['iso_checksum'],
'ISO_CHECKSUM_TYPE': build_data['iso_checksum_type'],
'ISO_URL': build_data['iso_url'],
'KUBERNETES_SEMVER': build_data['kubernetes_semver'],
'KUBERNETES_SOURCE': build_data['kubernetes_source'],
'KUBERNETES_VERSION': build_data['kubernetes_version'],
'KUBERNETES_SOURCE_TYPE': build_data['kubernetes_source_type'],
'POPULATED_DISK_SIZE': vmdk['size'],
'STREAM_DISK_SIZE': vmdk['stream_size'],
})
Expand Down Expand Up @@ -538,22 +536,20 @@ def stream_optimize_vmdk_files(inlist):
<Info>Information about the installed software</Info>
<Product>${OS_NAME} and Kubernetes ${KUBERNETES_SEMVER}</Product>
<Vendor>VMware Inc.</Vendor>
<Version>${CAPV_VERSION}+kube-${KUBERNETES_SEMVER}</Version>
<FullVersion>${CAPV_VERSION}+kube-${KUBERNETES_SEMVER}</FullVersion>
<Version>kube-${KUBERNETES_SEMVER}</Version>
<FullVersion>kube-${KUBERNETES_SEMVER}</FullVersion>
<ProductUrl>https://github.com/kubernetes-sigs/cluster-api-provider-vsphere</ProductUrl>
<VendorUrl>https://vmware.com</VendorUrl>
<Category>Cluster API Provider (CAPI)</Category>
<Property ovf:userConfigurable="false" ovf:value="${BUILD_TIMESTAMP}" ovf:type="string" ovf:key="BUILD_TIMESTAMP"></Property>
<Property ovf:userConfigurable="false" ovf:value="${BUILD_DATE}" ovf:type="string" ovf:key="BUILD_DATE"></Property>
<Property ovf:userConfigurable="false" ovf:value="${CAPI_VERSION}" ovf:type="string" ovf:key="CAPI_VERSION"></Property>
<Property ovf:userConfigurable="false" ovf:value="${CAPV_VERSION}" ovf:type="string" ovf:key="CAPV_VERSION"></Property>
<Property ovf:userConfigurable="false" ovf:value="${CNI_VERSION}" ovf:type="string" ovf:key="CNI_VERSION"></Property>
<Property ovf:userConfigurable="false" ovf:value="${ISO_URL}" ovf:type="string" ovf:key="ISO_URL"></Property>
<Property ovf:userConfigurable="false" ovf:value="${ISO_CHECKSUM}" ovf:type="string" ovf:key="ISO_CHECKSUM"></Property>
<Property ovf:userConfigurable="false" ovf:value="${ISO_CHECKSUM_TYPE}" ovf:type="string" ovf:key="ISO_CHECKSUM_TYPE"></Property>
<Property ovf:userConfigurable="false" ovf:value="${KUBERNETES_SEMVER}" ovf:type="string" ovf:key="KUBERNETES_SEMVER"></Property>
<Property ovf:userConfigurable="false" ovf:value="${KUBERNETES_SOURCE}" ovf:type="string" ovf:key="KUBERNETES_SOURCE"></Property>
<Property ovf:userConfigurable="false" ovf:value="${KUBERNETES_VERSION}" ovf:type="string" ovf:key="KUBERNETES_VERSION"></Property>
<Property ovf:userConfigurable="false" ovf:value="${KUBERNETES_SOURCE_TYPE}" ovf:type="string" ovf:key="KUBERNETES_SOURCE_TYPE"></Property>
</ProductSection>
</VirtualSystem>
</Envelope>
Expand Down
2 changes: 1 addition & 1 deletion images/capi/hack/image-new-kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
KUBE_RELEASE_SRC = "https://storage.googleapis.com/kubernetes-release"

KUBE_RESOLVED_SEM = "kubernetes_semver"
KUBE_RESOLVED_SRC = "kubernetes_source"
KUBE_RESOLVED_SRC = "kubernetes_http_source"
KUBE_RESOLVED_VER = "kubernetes_version"

# KubeVersionResolver is used for resolving Kubernetes version strings to the
Expand Down
33 changes: 19 additions & 14 deletions images/capi/packer/ami/packer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
"encrypted": "false",
"containerd_version": null,
"containerd_sha256": null,
"kubernetes_cni_version": null,
"kubernetes_cni_rpm_version": null,
"kubernetes_cni_deb_version": null,
"kubernetes_cni_semver": null,
"kubernetes_cni_source": null,
"kubernetes_cni_source_type": null,
"kubernetes_cni_http_source": null,
"kubernetes_semver": null,
"kubernetes_source": null,
"kubernetes_version": null,
"kubernetes_source_type": null,
"kubernetes_http_source": null,
"kubernetes_rpm_version": null,
"kubernetes_deb_version": null,
"kubernetes_rpm_repo": null,
"kubernetes_rpm_gpg_key": null,
"kubernetes_deb_repo": null,
"kubernetes_deb_gpg_key": null,
"kubernetes_rpm_gpg_check": null,
"kubernetes_container_registry": null,
"existing_ansible_ssh_args": "{{env `ANSIBLE_SSH_ARGS`}}",
"ami_groups": "all",
"ami_users": "",
Expand All @@ -40,7 +45,7 @@
"owners": ["099720109477"],
"most_recent": true
},
"ami_name": "capa-ami-ubuntu-18.04-{{user `kubernetes_version`}}-{{user `build_timestamp`}}",
"ami_name": "capa-ami-ubuntu-18.04-{{user `kubernetes_semver`}}-{{user `build_timestamp`}}",
"ami_groups": "{{user `ami_groups`}}",
"ami_users": "{{user `ami_users`}}",
"snapshot_groups": "{{user `snapshot_groups`}}",
Expand All @@ -58,8 +63,8 @@
"distribution": "Ubuntu",
"distribution_release": "bionic",
"distribution_version": "18.04",
"kubernetes_version": "{{user `kubernetes_version`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_version`}}"
"kubernetes_version": "{{user `kubernetes_semver`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_semver`}}"
}
},
{
Expand All @@ -77,7 +82,7 @@
"owners": ["410186602215"],
"most_recent": true
},
"ami_name": "capa-ami-centos-7-{{user `kubernetes_version`}}-{{user `build_timestamp`}}",
"ami_name": "capa-ami-centos-7-{{user `kubernetes_semver`}}-{{user `build_timestamp`}}",
"ami_groups": "{{user `ami_groups`}}",
"ami_users": "{{user `ami_users`}}",
"snapshot_groups": "{{user `snapshot_groups`}}",
Expand All @@ -96,8 +101,8 @@
"distribution": "CentOS",
"distribution_release": "Core",
"distribution_version": "7",
"kubernetes_version": "{{user `kubernetes_version`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_version`}}"
"kubernetes_version": "{{user `kubernetes_semver`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_semver`}}"
}
},
{
Expand All @@ -115,7 +120,7 @@
"owners": ["amazon"],
"most_recent": true
},
"ami_name": "capa-ami-amazon-2-{{user `kubernetes_version`}}-{{user `build_timestamp`}}",
"ami_name": "capa-ami-amazon-2-{{user `kubernetes_semver`}}-{{user `build_timestamp`}}",
"ami_groups": "{{user `ami_groups`}}",
"ami_users": "{{user `ami_users`}}",
"snapshot_groups": "{{user `snapshot_groups`}}",
Expand All @@ -133,8 +138,8 @@
"distribution": "Amazon Linux",
"distribution_release": "Amazon Linux 2",
"distribution_version": "2",
"kubernetes_version": "{{user `kubernetes_version`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_version`}}"
"kubernetes_version": "{{user `kubernetes_semver`}}",
"kubernetes_cni_version": "{{user `kubernetes_cni_semver`}}"
}
}
],
Expand All @@ -157,7 +162,7 @@
],
"extra_arguments": [
"--extra-vars",
"containerd_version={{user `containerd_version`}} containerd_sha256={{user `containerd_sha256`}} kubernetes_rpm_repo={{user `kubernetes_rpm_repo`}} kubernetes_rpm_gpg_key={{user `kubernetes_rpm_gpg_key`}} kubernetes_rpm_gpg_check={{user `kubernetes_rpm_gpg_check`}} kubernetes_deb_repo={{user `kubernetes_deb_repo`}} kubernetes_deb_gpg_key={{user `kubernetes_deb_gpg_key`}} kubernetes_cni_version={{user `kubernetes_cni_version`}} kubernetes_cni_semver={{user `kubernetes_cni_semver`}} kubernetes_cni_source={{user `kubernetes_cni_source`}} kubernetes_semver={{user `kubernetes_semver`}} kubernetes_source={{user `kubernetes_source`}} kubernetes_version={{user `kubernetes_version`}}"
"containerd_version={{user `containerd_version`}} containerd_sha256={{user `containerd_sha256`}} kubernetes_cni_http_source={{user `kubernetes_cni_http_source`}} kubernetes_http_source={{user `kubernetes_http_source`}} kubernetes_container_registry={{user `kubernetes_container_registry`}} kubernetes_rpm_repo={{user `kubernetes_rpm_repo`}} kubernetes_rpm_gpg_key={{user `kubernetes_rpm_gpg_key`}} kubernetes_rpm_gpg_check={{user `kubernetes_rpm_gpg_check`}} kubernetes_deb_repo={{user `kubernetes_deb_repo`}} kubernetes_deb_gpg_key={{user `kubernetes_deb_gpg_key`}} kubernetes_cni_deb_version={{user `kubernetes_cni_deb_version`}} kubernetes_cni_rpm_version={{user `kubernetes_cni_rpm_version`}} kubernetes_cni_semver={{user `kubernetes_cni_semver`}} kubernetes_cni_source_type={{user `kubernetes_cni_source_type`}} kubernetes_semver={{user `kubernetes_semver`}} kubernetes_source_type={{user `kubernetes_source_type`}} kubernetes_deb_version={{user `kubernetes_deb_version`}} kubernetes_rpm_version={{user `kubernetes_rpm_version`}}"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions images/capi/packer/config/cni.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"kubernetes_cni_semver": "v0.7.5",
"kubernetes_cni_version": "0.7.5-00",
"kubernetes_cni_source": "pkg"
"kubernetes_cni_rpm_version": "0.7.5-0",
"kubernetes_cni_deb_version": "0.7.5-00",
"kubernetes_cni_source_type": "pkg",
"kubernetes_cni_http_source": "https://github.com/containernetworking/plugins/releases/download"
}
11 changes: 7 additions & 4 deletions images/capi/packer/config/kubernetes.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"kubernetes_semver": "v1.15.3",
"kubernetes_version": "1.15.3-00",
"kubernetes_source": "pkg",
"kubernetes_rpm_version": "1.15.3-0",
"kubernetes_deb_version": "1.15.3-00",
"kubernetes_source_type": "pkg",
"kubernetes_http_source": "https://storage.googleapis.com/kubernetes-release/release",
"kubernetes_rpm_repo": "https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64",
"kubernetes_rpm_gpg_key": "\"https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg\"",
"kubernetes_rpm_gpg_check": "True",
"kubernetes_deb_repo": "\"https://apt.kubernetes.io/ kubernetes-xenial\"",
"kubernetes_deb_gpg_key": "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
}
"kubernetes_deb_gpg_key": "https://packages.cloud.google.com/apt/doc/apt-key.gpg",
"kubernetes_container_registry": "k8s.gcr.io"
}
Loading