From 96604324cfa8c771aeece0c31e18cd203d06f1f3 Mon Sep 17 00:00:00 2001 From: Egor Vasilyev Date: Tue, 9 Apr 2024 10:37:21 +0300 Subject: [PATCH] fix: Configure correct apt sources (#65) --- .github/workflows/pr-title.yml | 2 +- README.md | 37 +++++++++++----------- defaults/main.yml | 18 +++++++---- handlers/main.yml | 1 - molecule/default_ext-etcd-sec/molecule.yml | 4 ++- molecule/end-to-end/molecule.yml | 4 ++- tasks/configure.yml | 17 +++++++--- vars/main.yml | 2 -- 8 files changed, 49 insertions(+), 36 deletions(-) delete mode 100644 handlers/main.yml delete mode 100644 vars/main.yml diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index c14bc9b..ae1181e 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -4,8 +4,8 @@ on: pull_request_target: types: - opened + - reopened - edited - - synchronize jobs: pr-title: diff --git a/README.md b/README.md index 87a6c27..2ef159c 100644 --- a/README.md +++ b/README.md @@ -17,25 +17,24 @@ Role Variables All variables are defined as defaults in [defaults/main.yml](defaults/main.yml) and may be overrided. -| Name | Default value | Description | -|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `k8s_cluster_kubelet_version` | 1.26.0-00 | kubelet version | -| `k8s_cluster_kubeadm_version` | 1.26.0-00 | kubeadm version | -| `k8s_cluster_kubectl_version` | 1.26.0-00 | kubectl version | -| `k8s_cluster_apt_key_url` | https://packages.cloud.google.com/apt/doc/apt-key.gpg | Apt key url | -| `k8s_cluster_apt_repository` | deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main | Apt repository | -| `k8s_cluster_kubernetes_version` | 1.26.0 | Kubernetes version | -| `k8s_cluster_kubelet_config_root_dir` | /etc/kubernetes | Default kubelet configuration directory | -| `k8s_cluster_node_type` | worker | Default node type. If you need to init or join master, you should set this variable to 'master' | -| `k8s_cluster_node_name` | inventory_hostname | Name of k8s node | -| `k8s_cluster_initial_master` | false | This variable identifies initial master node to initialize cluster. It should be assigned to the only node with 'true' value | -| `k8s_cluster_init_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: InitConfiguration` of the cluster in pure yaml format | -| `k8s_cluster_cluster_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: ClusterConfiguration` of the cluster in pure yaml format | -| `k8s_cluster_kubelet_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: KubeletConfiguration` in pure yaml format | -| `k8s_cluster_kubeproxy_configuration` | "" | Represents `kind: KubeproxyConfiguration` in pure yaml format | -| `k8s_cluster_join_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: JoinConfiguration` of the cluster in pure yaml format | -| `k8s_cluster_flannel_apply` | https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml | Default Flannel manifest. Read more about [Flannel](https://github.com/flannel-io/flannel) | -| `k8s_cluster_custom_networking_tasks_path` | "" | Path to file with a set of tasks to configure networking. It could be a set of tasks or even `include_role` statement. It will run only once during cluster initialization | +| Name | Default value | Description | +|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `k8s_cluster_kube_version` | 1.28.8-1.1 | `kubelet`, `kubeadm` and `kubectl` versions | +| `k8s_cluster_apt_key_url` | https://packages.cloud.google.com/apt/doc/apt-key.gpg | Apt key url | +| `k8s_cluster_apt_key_file` | /usr/share/keyrings/kubernetes-archive-keyring.gpg | Apt key file | +| `k8s_cluster_apt_repository` | deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main | Apt repository | +| `k8s_cluster_kubernetes_version` | 1.28.8 | Kubernetes version | +| `k8s_cluster_kubelet_config_root_dir` | /etc/kubernetes | Default kubelet configuration directory | +| `k8s_cluster_node_type` | worker | Default node type. If you need to init or join master, you should set this variable to 'master' | +| `k8s_cluster_node_name` | inventory_hostname | Name of k8s node | +| `k8s_cluster_initial_master` | false | This variable identifies initial master node to initialize cluster. It should be assigned to the only node with 'true' value | +| `k8s_cluster_init_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: InitConfiguration` of the cluster in pure yaml format | +| `k8s_cluster_cluster_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: ClusterConfiguration` of the cluster in pure yaml format | +| `k8s_cluster_kubelet_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: KubeletConfiguration` in pure yaml format | +| `k8s_cluster_kubeproxy_configuration` | "" | Represents `kind: KubeproxyConfiguration` in pure yaml format | +| `k8s_cluster_join_configuration` | See [defaults/main.yml](defaults/main.yml) | Represents `kind: JoinConfiguration` of the cluster in pure yaml format | +| `k8s_cluster_flannel_apply` | https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml | Default Flannel manifest. Read more about [Flannel](https://github.com/flannel-io/flannel) | +| `k8s_cluster_custom_networking_tasks_path` | "" | Path to file with a set of tasks to configure networking. It could be a set of tasks or even `include_role` statement. It will run only once during cluster initialization | \* except `apiVersion` and `kind` fields diff --git a/defaults/main.yml b/defaults/main.yml index fb58be7..751289f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,13 +1,19 @@ --- -k8s_cluster_kubelet_version: '1.26.0-00' -k8s_cluster_kubeadm_version: '1.26.0-00' -k8s_cluster_kubectl_version: '1.26.0-00' +# common version for kubernetes related applications - kubelet, kubeadm, kubectl +k8s_cluster_kube_version: 1.28.8-1.1 -k8s_cluster_apt_key_url: 'https://packages.cloud.google.com/apt/doc/apt-key.gpg' -k8s_cluster_apt_repository: 'deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main' +# read more at the following sources: +# https://kubernetes.io/blog/2023/08/31/legacy-package-repository-deprecation/ +# https://kubernetes.io/blog/2023/08/15/pkgs-k8s-io-introduction/ +# +# 'k8s_cluster_apt_kubernetes_version' will be calculated during role execution using set_fact +k8s_cluster_apt_key_url: "https://pkgs.k8s.io/core:/stable:/{{ k8s_cluster_apt_kubernetes_version }}/deb/Release.key" +k8s_cluster_apt_key_file: "/usr/share/keyrings/kubernetes-archive-keyring.gpg" +k8s_cluster_apt_repository: 'deb [signed-by={{ k8s_cluster_apt_key_file }}] https://pkgs.k8s.io/core:/stable:/{{ k8s_cluster_apt_kubernetes_version }}/deb/ /' -k8s_cluster_kubernetes_version: 1.26.0 +# without leading 'v', numbers and dots only +k8s_cluster_kubernetes_version: 1.28.8 k8s_cluster_kubelet_config_root_dir: '/etc/kubernetes' k8s_cluster_node_type: worker diff --git a/handlers/main.yml b/handlers/main.yml deleted file mode 100644 index ed97d53..0000000 --- a/handlers/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/molecule/default_ext-etcd-sec/molecule.yml b/molecule/default_ext-etcd-sec/molecule.yml index ed54c8a..c36b94a 100644 --- a/molecule/default_ext-etcd-sec/molecule.yml +++ b/molecule/default_ext-etcd-sec/molecule.yml @@ -51,7 +51,7 @@ provisioner: host_vars: k8s-control-plane-01: k8s_cluster_initial_master: true - k8s_cluster_kubernetes_version: 1.26.0 + k8s_cluster_kubernetes_version: 1.28.8 k8s_cluster_cluster_configuration: etcd: external: @@ -89,6 +89,8 @@ provisioner: all: # cloudlabsinfra.etcd_cluster_certificates role related variables etcd_cert_dir: /etc/ssl/private + # k8s_cluster role related variables + k8s_cluster_kube_version: 1.28.8-1.1 control_plane: k8s_cluster_node_type: "master" etcd_cert_matrix: diff --git a/molecule/end-to-end/molecule.yml b/molecule/end-to-end/molecule.yml index 8a9fae0..d3e0674 100644 --- a/molecule/end-to-end/molecule.yml +++ b/molecule/end-to-end/molecule.yml @@ -93,7 +93,6 @@ provisioner: k8s-control-plane-01: # cloudlabsinfra.k8s_cluster role related variables k8s_cluster_initial_master: true - k8s_cluster_kubernetes_version: 1.26.0 # we can't use default cluster configuration here because it doesn't have 'etcd' section k8s_cluster_cluster_configuration: etcd: @@ -149,6 +148,9 @@ provisioner: all: # required for control-plane nodes and etcd as well etcd_frontend_name: "etcd.cloudlabsinfra.local" + # k8s_cluster role related variables + k8s_cluster_kube_version: 1.28.8-1.1 + k8s_cluster_kubernetes_version: 1.28.8 k8s_cluster_control_plane_endpoint: "control-plane.cloudlabsinfra.local" control_plane: # default value of variable below is 'worker' diff --git a/tasks/configure.yml b/tasks/configure.yml index 4648362..1871400 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -14,24 +14,31 @@ state: present update_cache: yes + - name: Set proper version for apt repo + ansible.builtin.set_fact: + # input: 1.27.1 or 1.27.13 or v1.27.13 + # output: v1.27 + # first slash escapes second slash + k8s_cluster_apt_kubernetes_version: "{{ k8s_cluster_kubernetes_version | regex_replace('^v?(\\d\\.\\d\\d)\\.\\d*$', 'v\\1') }}" + - name: Add Kubernetes apt key ansible.builtin.apt_key: url: "{{ k8s_cluster_apt_key_url }}" - keyring: /usr/share/keyrings/kubernetes-archive-keyring.gpg + keyring: "{{ k8s_cluster_apt_key_file }}" - name: Add Kubernetes apt repository ansible.builtin.apt_repository: repo: "{{ k8s_cluster_apt_repository }}" state: present - # filename: kubernetes + #filename: kubernetes update_cache: true - name: Install Kubernetes components ansible.builtin.apt: name: - - kubelet={{ k8s_cluster_kubelet_version }} - - kubeadm={{ k8s_cluster_kubeadm_version }} - - kubectl={{ k8s_cluster_kubectl_version }} + - kubelet={{ k8s_cluster_kube_version }} + - kubeadm={{ k8s_cluster_kube_version }} + - kubectl={{ k8s_cluster_kube_version }} allow_unauthenticated: yes update_cache: yes diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index 15da365..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for ansible_k8s_cluster