Browse Source

Merge pull request #840 from Lakshmi-Patneedi/devel

K8s_common role changes for omnia.yml
Sujit Jadhav 3 years ago
parent
commit
98ca729dc9

+ 120 - 28
roles/k8s_common/tasks/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -13,19 +13,6 @@
 #  limitations under the License.
 ---
 
-- name: Add kubernetes repo
-  yum_repository:
-    name: kubernetes
-    description: kubernetes
-    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
-    enabled: yes
-    gpgcheck: no
-    repo_gpgcheck: no
-    gpgkey:
-      - https://packages.cloud.google.com/yum/doc/yum-key.gpg
-      - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
-  tags: install
-
 - name: Update sysctl to handle incorrectly routed traffic when iptables is bypassed
   copy:
     src: k8s.conf
@@ -40,20 +27,125 @@
   changed_when: true
   tags: install
 
-- name: Install k8s packages
-  package:
-    name: "{{ k8s_packages }}"
-    state: present
-  tags: install
+- block:
+    - name: Add kubernetes repo
+      yum_repository:
+        name: kubernetes
+        description: kubernetes
+        baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
+        enabled: yes
+        gpgcheck: no
+        repo_gpgcheck: no
+        gpgkey:
+          - https://packages.cloud.google.com/yum/doc/yum-key.gpg
+          - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
+      tags: install
 
-- name: Versionlock kubernetes
-  command: "yum versionlock '{{ item }}'"
-  args:
-    warn: false
-  with_items:
-    - "{{ k8s_packages }}"
-  changed_when: true
-  tags: install
+    - name: Install k8s packages
+      package:
+        name: "{{ k8s_packages }}"
+        state: present
+      tags: install
+
+    - name: Versionlock kubernetes
+      command: "yum versionlock '{{ item }}'"
+      args:
+        warn: false
+      with_items:
+        - "{{ k8s_packages }}"
+      changed_when: true
+      tags: install
+  when: os_supported_leap not in compute_os
+
+- block:
+    - name: Add kubernetes repo
+      zypper_repository:
+        name: google-k8s
+        repo: "{{ k8s_repo_leap }}"
+        state: present
+        autorefresh: yes
+        disable_gpg_check: yes
+      tags: install
+
+    - name: Import rpm-package key for installing kubernetes
+      rpm_key:
+        key: "{{ rpm_pkg_leap }}"
+        state: present
+      tags: install
+
+    - name: Import yum key for installing kubernetes
+      rpm_key:
+        key: "{{ yum_key_leap }}"
+        state: present
+      tags: install
+
+    - name: Import gpg-pubkey key for installing kubernetes
+      command: "{{ gpg_pubkey_leap }}"
+      args:
+        warn: false
+      changed_when: false
+      tags: install
+
+    - name: Refresh repositories and installing conntrack-tools
+      package:
+        name: conntrack-tools
+        state: present
+      tags: install
+
+    - name: Install Kubeadm
+      ansible.builtin.expect:
+        command: zypper install --oldpackage "{{ kubeadm_version }}"
+        responses:
+            (.*) [1/2/c/d/?](.): '2'
+            (.*)(y): 'y'
+      register: kubeadm_status
+      until: kubeadm_status is not failed
+      retries: "{{ max_retries }}"
+      tags: install
+
+    - name: Install Kubelet
+      ansible.builtin.expect:
+        command: zypper install --oldpackage "{{ kubelet_version }}"
+        responses:
+            (.*) [1/2/c/d/?](.): '2'
+            (.*)(y): 'y'
+      register: kubelet_status
+      until: kubelet_status is not failed
+      retries: "{{ max_retries }}"
+      tags: install
+
+    - name: Install Kubectl
+      zypper:
+        name: "{{ kubectl_version }}"
+        state: present
+        oldpackage: yes
+        force: yes
+      register: kubectl_status
+      until: kubectl_status is not failed
+      retries: "{{ max_retries }}"
+      tags: install
+
+    - name: Versionlocking kubeadm
+      command: zypper addlock "{{ kubeadm_version }}"
+      args:
+        warn: false
+      changed_when: false
+      tags: install
+
+    - name: Versionlocking kubectl
+      command: zypper addlock "{{ kubelet_version }}"
+      args:
+        warn: false
+      changed_when: false
+      tags: install
+
+    - name: Versionlocking kubelet
+      command: zypper addlock "{{ kubectl_version }}"
+      args:
+        warn: false
+      changed_when: false
+      tags: install
+  when: ( os_supported_leap in compute_os ) and ( ansible_distribution_version >= os_supported_leap_version )
 
 - name: Start and enable docker service
   service:
@@ -66,4 +158,4 @@
   service:
     name: kubelet
     state: restarted
-    enabled: yes
+    enabled: yes

+ 14 - 2
roles/k8s_common/vars/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -12,6 +12,18 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 ---
+k8s_repo_leap: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
+rpm_pkg_leap: https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
+yum_key_leap:  https://packages.cloud.google.com/yum/doc/yum-key.gpg
+gpg_pubkey_leap: "rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}'"
+docker_repo_url_leap: https://download.docker.com/linux/sles/docker-ce.repo
+docker_repo_dest_leap: /etc/YaST2/docker-ce.repo
+os_supported_leap: "leap"
+os_supported_leap_version: "15.3"
+kubeadm_version: "kubeadm-{{ hostvars['127.0.0.1']['k8s_version'] }}"
+kubelet_version: "kubelet-{{ hostvars['127.0.0.1']['k8s_version'] }}"
+kubectl_version: "kubectl-{{ hostvars['127.0.0.1']['k8s_version'] }}"
+max_retries: 20
 
 k8s_packages:
   - "kubelet-{{ hostvars['127.0.0.1']['k8s_version'] }}"
@@ -24,4 +36,4 @@ k8s_conf_dest: /etc/sysctl.d/
 
 k8s_repo_file_mode: 0644
 
-k8s_conf_file_mode: 0644
+k8s_conf_file_mode: 0644

+ 3 - 3
roles/k8s_start_manager/tasks/main.yml

@@ -1,4 +1,4 @@
-#  Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
+#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@
 - name: Initialize kubeadm (This process may take 5-10min)
   block:
     - name: Initialize kubeadm (This process may take 5-10min)
-      command: "/bin/kubeadm init --pod-network-cidr='{{ hostvars['127.0.0.1']['k8s_pod_network_cidr'] }}' \
+      command: "kubeadm init --pod-network-cidr='{{ hostvars['127.0.0.1']['k8s_pod_network_cidr'] }}' \
         --apiserver-advertise-address='{{ ansible_default_ipv4.address }}'"
       changed_when: true
       register: init_output
@@ -80,7 +80,7 @@
       changed_when: true
 
     - name: Initialize kubeadm (This process may take 5-10min)
-      command: "/bin/kubeadm init --pod-network-cidr='{{ hostvars['127.0.0.1']['k8s_pod_network_cidr'] }}' \
+      command: "kubeadm init --pod-network-cidr='{{ hostvars['127.0.0.1']['k8s_pod_network_cidr'] }}' \
         --apiserver-advertise-address='{{ ansible_default_ipv4.address }}'"
       changed_when: true
       register: init_output

+ 23 - 0
tools/copy_files_container.yml

@@ -0,0 +1,23 @@
+#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+---
+- name: Fetching container files
+  hosts: localhost
+  tasks:
+  - name: Include vars file
+    include_vars: "pod_details.yml"
+
+  - name: Copying files from container env
+    command: "kubectl cp {{ pod_name }}:{{ container_file_location | regex_replace('^\\/', '') }} {{ local_folder_location }} -n {{ namespace }} -c {{ container_name }}"
+    changed_when: true

+ 25 - 0
tools/pod_details.yml

@@ -0,0 +1,25 @@
+#  Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+---
+# namespace: Namespace of container from which files needs to retrived
+# pod_name: Name of the pod
+# container_file_location: The file/folder which needs to be saved on local machine
+# local_folder_location: Local machine location, on which retrived files need to be saved
+# container_name: Name of the container from which files needs to be retrived
+# Note: All fields are mandatory
+namespace:
+pod_name:
+container_file_location:
+local_folder_location:
+container_name: