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

Add check function for DaemonSet #62

Merged
merged 1 commit into from
Sep 30, 2024
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
21 changes: 20 additions & 1 deletion kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,33 @@ func (k *Kubectl) ApplyJSON(namespace string, name string, v interface{}) error

// Delete calls kubectl with the given arguments
func (k *Kubectl) Delete(args ...string) error {

if _, err := runBinary(kubeCtlCmd, append([]string{"delete"}, args...)...); err != nil {
return errors.Wrapf(err, "Deleting resource: %s", args)
}

return nil
}

// WaitForDaemonSet blocks until daemonset matching the label is available in the specified namespace. It fails after the timeout.
func (k *Kubectl) WaitForDaemonSet(namespace string, label string) error {
return wait.PollImmediate(k.PollInterval, k.PollTimeout, func() (bool, error) {
return k.DaemonSetReady(namespace, label)
})
}

// DaemonSetReady returns true if daemontset by that label is present in the given namespace
func (k *Kubectl) DaemonSetReady(namespace string, label string) (bool, error) {
out, err := runBinary(kubeCtlCmd, "rollout", "status", "daemonset", "--namespace", namespace, "--selector", label)
if err == nil {
if !strings.Contains(string(out), "successfully rolled out") {
return false, err
}
return true, nil
}

return false, errors.Wrapf(err, "Kubectl rollout failed for label %s. %s", label, string(out))
}

// ConfigMap defines a kube ConfigMap
type ConfigMap struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
Expand Down
17 changes: 17 additions & 0 deletions rancher/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ func SetRole(ns, name, pool, role string, value bool) error {
return c.setCluster(ns)
}

/**
* Check daemonset status
* @remarks This function checks the status of a daemonset based on checkList
* @param k Already defined Kubectl context
* @param checkList Array of paired namespaces/labels to check
* @example CheckDaemonSet(k, [][]string{{"kube-system", "k8s-app=canal"}})
* @returns Nothing or an error
*/
func CheckDaemonSet(k *kubectl.Kubectl, checkList [][]string) error {
for _, check := range checkList {
if err := k.WaitForDaemonSet(check[0], check[1]); err != nil {
return err
}
}
return nil
}

/**
* Check pod status
* @remarks This function checks the status of a pod based on checkList
Expand Down
Loading