From c2c9a70d97bb051cf0579833246516c6cd987445 Mon Sep 17 00:00:00 2001
From: Igor Pires Soares <Igor.PiresSoares@windriver.com>
Date: Fri, 29 Nov 2024 17:50:08 +0000
Subject: [PATCH] Revert "Add instrumentation log for kubeadm join command"

This reverts commit b1ec6538c6daeb21c01f59b74196b87bf99040ec.

Reason for revert: Fix an issue where puppet doesn't stop when a command
fails. Also aims to fix kubeadm join failures when unlocking
controller-1 after Backup & Restore.

This also enforces Zuul to use python 3.9, since it was running tox checks with python 3.12.

Closes-bug: 2090224
Change-Id: Iebb76674e45f82563d9901b44cf0afe44a436822
---
 .zuul.yaml                                    | 26 +++++++++++---
 .../modules/platform/manifests/kubernetes.pp  | 34 ++++++++-----------
 2 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/.zuul.yaml b/.zuul.yaml
index 71e09f1da..585abffbf 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -5,13 +5,13 @@
     check:
       jobs:
         - stx-puppet-linters
-        - openstack-tox-pep8
-        - openstack-tox-pylint
+        - stx-puppet-tox-pep8
+        - stx-puppet-tox-pylint
     gate:
       jobs:
         - stx-puppet-linters
-        - openstack-tox-pep8
-        - openstack-tox-pylint
+        - stx-puppet-tox-pep8
+        - stx-puppet-tox-pylint
     post:
       jobs:
         - stx-stx-puppet-upload-git-mirror
@@ -23,6 +23,24 @@
       Run linters for stx-puppet
     pre-run: playbooks/tox-puppet-lint/pre.yaml
 
+- job:
+    name: stx-puppet-tox-pep8
+    parent: openstack-tox-pep8
+    nodeset: debian-bullseye
+    description: |
+      Run pep8 checks for stx-puppet
+    vars:
+      python_version: 3.9
+
+- job:
+    name: stx-puppet-tox-pylint
+    parent: openstack-tox-pylint
+    nodeset: debian-bullseye
+    description: |
+      Run pylint checks for stx-puppet
+    vars:
+      python_version: 3.9
+
 - job:
     name: stx-stx-puppet-upload-git-mirror
     parent: upload-git-mirror
diff --git a/puppet-manifests/src/modules/platform/manifests/kubernetes.pp b/puppet-manifests/src/modules/platform/manifests/kubernetes.pp
index c8d46b73b..634b64da6 100644
--- a/puppet-manifests/src/modules/platform/manifests/kubernetes.pp
+++ b/puppet-manifests/src/modules/platform/manifests/kubernetes.pp
@@ -236,10 +236,9 @@ class platform::kubernetes::cgroup
 define platform::kubernetes::kube_command (
   $command,
   $logname,
-  $environment = [],
+  $environment = undef,
   $timeout = undef,
-  $onlyif = undef,
-  $unless = undef
+  $onlyif = undef
 ) {
   # Execute kubernetes command with instrumentation.
   # Note that puppet captures no command output on timeout.
@@ -251,12 +250,11 @@ define platform::kubernetes::kube_command (
   # by puppet-manifest-apply.sh command.
 
   exec { "${title}": # lint:ignore:only_variable_string
-    environment => $environment,
+    environment => [ $environment ],
     provider    => shell,
     command     => "stdbuf -oL -eL ${command} |& tee /var/log/puppet/latest/${logname}",
     timeout     => $timeout,
     onlyif      => $onlyif,
-    unless      => $unless,
     logoutput   => true,
   }
 }
@@ -453,10 +451,9 @@ class platform::kubernetes::master::init
       local_registry_auth => $local_registry_auth,
     }
 
-    -> platform::kubernetes::kube_command { 'configure master node':
-      command => $join_cmd,
-      logname => 'kubeadm-join-command.log',
-      timeout => 300,
+    -> exec { 'configure master node':
+      command   => $join_cmd,
+      logoutput => true,
     }
 
     # Update ownership/permissions for file created by "kubeadm init".
@@ -663,11 +660,10 @@ class platform::kubernetes::worker::init
 
   # Configure the worker node. Only do this once, so check whether the
   # kubelet.conf file has already been created (by the join).
-  platform::kubernetes::kube_command { 'configure worker node':
-    command => $join_cmd,
-    logname => 'kubeadm-join-command.log',
-    unless  => 'test -f /etc/kubernetes/kubelet.conf',
-    timeout => 300,
+  exec { 'configure worker node':
+    command   => $join_cmd,
+    logoutput => true,
+    unless    => 'test -f /etc/kubernetes/kubelet.conf',
   }
 
   # Add kubelet service override
@@ -973,7 +969,7 @@ class platform::kubernetes::upgrade_first_control_plane
     command     => "kubeadm -v6 upgrade apply ${version} \
                     --allow-experimental-upgrades --allow-release-candidate-upgrades -y",
     logname     => 'kubeadm-upgrade-apply.log',
-    environment => [ 'KUBECONFIG=/etc/kubernetes/admin.conf' ],
+    environment => 'KUBECONFIG=/etc/kubernetes/admin.conf',
     timeout     => 210,
   }
   -> exec { 'purge all kubelet-config except most recent':
@@ -1033,7 +1029,7 @@ class platform::kubernetes::upgrade_control_plane
   platform::kubernetes::kube_command { 'upgrade_control_plane':
     command     => 'kubeadm -v6 upgrade node',
     logname     => 'kubeadm-upgrade-node.log',
-    environment => [ 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf' ],
+    environment => 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf',
     timeout     => 210,
   }
 
@@ -1177,7 +1173,7 @@ class platform::kubernetes::worker::upgrade_kubelet
     # The -v6 gives verbose debug output includes health, GET response, delay.
     command     => "/usr/local/kubernetes/${kubeadm_version}/stage1/usr/bin/kubeadm -v6 upgrade node",
     logname     => 'kubeadm-upgrade-node.log',
-    environment => [ 'KUBECONFIG=/etc/kubernetes/kubelet.conf' ],
+    environment => 'KUBECONFIG=/etc/kubernetes/kubelet.conf',
     timeout     => 300,
   }
   -> Class['platform::kubernetes::mask_stop_kubelet']
@@ -1926,7 +1922,7 @@ class platform::kubernetes::update_kubelet_config::runtime
   platform::kubernetes::kube_command { 'update kubelet config':
     command     => 'kubeadm upgrade node phase kubelet-config',
     logname     => 'kubeadm-upgrade-node-phase-kubelet-config.log',
-    environment => [ 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf' ],
+    environment => 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf',
     timeout     => 60,
   }
 
@@ -1959,7 +1955,7 @@ class platform::kubernetes::cordon_node {
                     --skip-wait-for-delete-timeout=10 \
                     --force --timeout=150s",
     logname     => 'cordon.log',
-    environment => [ 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf' ],
+    environment => 'KUBECONFIG=/etc/kubernetes/admin.conf:/etc/kubernetes/kubelet.conf',
     onlyif      => "kubectl get node ${::platform::params::hostname}",
   }
 }