Skip to content

Commit

Permalink
test/gke: Only restart kube-system pods if not Cilium managed
Browse files Browse the repository at this point in the history
Instead of restarting all kube-system pods, restart the unmanaged pods.

Signed-off-by: Thomas Graf <thomas@cilium.io>
  • Loading branch information
tgraf committed May 22, 2020
1 parent ac1e7a8 commit cc84c1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
38 changes: 38 additions & 0 deletions test/helpers/kubectl.go
Expand Up @@ -1777,6 +1777,44 @@ func (kub *Kubectl) ValidateKubernetesDNS() error {
return nil
}

// RestartUnmanagedPodsInNamespace restarts all pods in a namespace which are:
// * not host networking
// * not managed by Cilium already
func (kub *Kubectl) RestartUnmanagedPodsInNamespace(namespace string, excludePodPrefix ...string) {
podList := &v1.PodList{}
cmd := KubectlCmd + " -n " + namespace + " get pods -o json"
res := kub.ExecShort(cmd)
if !res.WasSuccessful() {
ginkgoext.Failf("Unable to retrieve all pods to restart unmanaged pods with '%s': %s", cmd, res.OutputPrettyPrint())
}
if err := res.Unmarshal(podList); err != nil {
ginkgoext.Failf("Unable to unmarshal podlist: %s", err)
}

iteratePods:
for _, pod := range podList.Items {
if pod.Spec.HostNetwork {
continue
}

for _, prefix := range excludePodPrefix {
if strings.HasPrefix(pod.Name, prefix) {
continue iteratePods
}
}

ep, err := kub.GetCiliumEndpoint(namespace, pod.Name)
if err != nil || ep.Identity == nil || ep.Identity.ID == 0 {
ginkgoext.By("Restarting unmanaged pod %s/%s", namespace, pod.Name)
cmd = KubectlCmd + " -n " + namespace + " delete pod " + pod.Name
res = kub.ExecShort(cmd)
if !res.WasSuccessful() {
ginkgoext.Failf("Unable to restart unmanaged pod with '%s': %s", cmd, res.OutputPrettyPrint())
}
}
}
}

// RedeployKubernetesDnsIfNecessary validates if the Kubernetes DNS is
// functional and re-deploys it if it is not and then waits for it to deploy
// successfully and become operational. See ValidateKubernetesDNS() for the
Expand Down
5 changes: 1 addition & 4 deletions test/k8sT/assertionHelpers.go
Expand Up @@ -128,10 +128,7 @@ func DeployCiliumOptionsAndDNS(vm *helpers.Kubectl, ciliumFilename string, optio

switch helpers.GetCurrentIntegration() {
case helpers.CIIntegrationGKE:
By("Restarting all kube-system pods")
if res := vm.DeleteResource("pod", fmt.Sprintf("-n %s --all", helpers.KubeSystemNamespace)); !res.WasSuccessful() {
log.Warningf("Unable to delete kube-system pods: %s", res.OutputPrettyPrint())
}
vm.RestartUnmanagedPodsInNamespace(helpers.KubeSystemNamespace)
}

switch helpers.GetCurrentIntegration() {
Expand Down

0 comments on commit cc84c1d

Please sign in to comment.