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

cleanups: fix linter issues 20231026 #237

Merged
merged 5 commits into from
Oct 26, 2023
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
8 changes: 4 additions & 4 deletions pkg/deployer/wait/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
func (wt Waiter) ForCRDCreated(ctx context.Context, name string) (*apiextensionv1.CustomResourceDefinition, error) {
key := ObjectKey{Name: name}
crd := &apiextensionv1.CustomResourceDefinition{}
err := k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
err := wt.Cli.Get(ctx, key.AsKey(), crd)
err := k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
err := wt.Cli.Get(fctx, key.AsKey(), crd)
if err != nil {
wt.Log.Info("failed to get the CRD", "key", key.String(), "error", err)
return false, err
Expand All @@ -40,10 +40,10 @@ func (wt Waiter) ForCRDCreated(ctx context.Context, name string) (*apiextensionv
}

func (wt Waiter) ForCRDDeleted(ctx context.Context, name string) error {
return k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
return k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
obj := apiextensionv1.CustomResourceDefinition{}
key := ObjectKey{Name: name}
err := wt.Cli.Get(ctx, key.AsKey(), &obj)
err := wt.Cli.Get(fctx, key.AsKey(), &obj)
return deletionStatusFromError(wt.Log, "CRD", key, err)
})
}
8 changes: 4 additions & 4 deletions pkg/deployer/wait/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

func (wt Waiter) ForDaemonSetReadyByKey(ctx context.Context, key ObjectKey) (*appsv1.DaemonSet, error) {
updatedDs := &appsv1.DaemonSet{}
err := k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
err := wt.Cli.Get(ctx, key.AsKey(), updatedDs)
err := k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
err := wt.Cli.Get(fctx, key.AsKey(), updatedDs)
if err != nil {
wt.Log.Info("failed to get the daemonset", "key", key.String(), "error", err)
return false, err
Expand Down Expand Up @@ -57,10 +57,10 @@ func AreDaemonSetPodsReady(newStatus *appsv1.DaemonSetStatus) bool {
}

func (wt Waiter) ForDaemonSetDeleted(ctx context.Context, namespace, name string) error {
return k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
return k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
obj := appsv1.DaemonSet{}
key := ObjectKey{Name: name, Namespace: namespace}
err := wt.Cli.Get(ctx, key.AsKey(), &obj)
err := wt.Cli.Get(fctx, key.AsKey(), &obj)
return deletionStatusFromError(wt.Log, "DaemonSet", key, err)
})
}
8 changes: 4 additions & 4 deletions pkg/deployer/wait/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

func (wt Waiter) ForDeploymentCompleteByKey(ctx context.Context, key ObjectKey, replicas int32) (*appsv1.Deployment, error) {
updatedDp := &appsv1.Deployment{}
err := k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
err := wt.Cli.Get(ctx, key.AsKey(), updatedDp)
err := k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
err := wt.Cli.Get(fctx, key.AsKey(), updatedDp)
if err != nil {
wt.Log.Info("failed to get the deployment", "key", key.String(), "error", err)
return false, err
Expand Down Expand Up @@ -62,10 +62,10 @@ func areDeploymentReplicasAvailable(newStatus *appsv1.DeploymentStatus, replicas
}

func (wt Waiter) ForDeploymentDeleted(ctx context.Context, namespace, name string) error {
return k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
return k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
obj := appsv1.Deployment{}
key := ObjectKey{Name: name, Namespace: namespace}
err := wt.Cli.Get(ctx, key.AsKey(), &obj)
err := wt.Cli.Get(fctx, key.AsKey(), &obj)
return deletionStatusFromError(wt.Log, "Deployment", key, err)
})
}
4 changes: 2 additions & 2 deletions pkg/deployer/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func (wt *Waiter) Interval(iv time.Duration) *Waiter {
func (wt Waiter) ForNamespaceDeleted(ctx context.Context, namespace string) error {
log := wt.Log.WithValues("namespace", namespace)
log.Info("wait for the namespace to be gone")
return k8swait.PollImmediate(wt.PollInterval, wt.PollTimeout, func() (bool, error) {
return k8swait.PollUntilContextTimeout(ctx, wt.PollInterval, wt.PollTimeout, true, func(fctx context.Context) (bool, error) {
nsKey := ObjectKey{Name: namespace}
ns := corev1.Namespace{} // unused
err := wt.Cli.Get(ctx, nsKey.AsKey(), &ns)
err := wt.Cli.Get(fctx, nsKey.AsKey(), &ns)
return deletionStatusFromError(wt.Log, "Namespace", nsKey, err)
})
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/kubeletconfig/configz.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ import (
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
)

func GetKubeletConfigForNodes(kc *Kubectl, nodeNames []string, logger logr.Logger) (map[string]*kubeletconfigv1beta1.KubeletConfiguration, error) {
func GetKubeletConfigForNodes(kc *Kubectl, nodeNames []string, logger logr.Logger) (k8sconf map[string]*kubeletconfigv1beta1.KubeletConfiguration, err error) {
cmd := kc.Command("proxy", "-p", "0")
stdout, stderr, err := StartWithStreamOutput(cmd)
var stdout, stderr io.ReadCloser
stdout, stderr, err = StartWithStreamOutput(cmd)
if err != nil {
return nil, err
}
defer stdout.Close()
defer stderr.Close()
defer cmd.Process.Kill()
defer func() { err = cmd.Process.Kill() }()

port, err := FindProxyPort(stdout)
if err != nil {
Expand All @@ -48,7 +52,7 @@ func GetKubeletConfigForNodes(kc *Kubectl, nodeNames []string, logger logr.Logge
}
client := &http.Client{Transport: tr}

kubeletConfs := make(map[string]*kubeletconfigv1beta1.KubeletConfiguration)
k8sconf = make(map[string]*kubeletconfigv1beta1.KubeletConfiguration)
for _, nodeName := range nodeNames {
endpoint := fmt.Sprintf("http://127.0.0.1:%d/api/v1/nodes/%s/proxy/configz", port, nodeName)

Expand All @@ -64,6 +68,7 @@ func GetKubeletConfigForNodes(kc *Kubectl, nodeNames []string, logger logr.Logge
logger.Info("request creation failed - skipped", "endpoint", endpoint, "error", err)
continue
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
logger.Info("unexpected response status code - skipped", "endpoint", endpoint, "statusCode", resp.StatusCode)
continue
Expand All @@ -75,9 +80,9 @@ func GetKubeletConfigForNodes(kc *Kubectl, nodeNames []string, logger logr.Logge
continue
}

kubeletConfs[nodeName] = conf
k8sconf[nodeName] = conf
}
return kubeletConfs, nil
return k8sconf, nil
}

func FindProxyPort(r io.Reader) (int, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/manifests/schedparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func DecodeSchedulerProfilesFromData(data []byte) ([]ConfigParams, error) {
}

return params, nil

}

func FindSchedulerProfileByName(profileParams []ConfigParams, schedulerName string) *ConfigParams {
Expand Down
6 changes: 5 additions & 1 deletion pkg/objectupdate/sched/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ func RenderConfig(data []byte, schedulerName string, params *manifests.ConfigPar
}

if params.ProfileName != "" {
unstructured.SetNestedField(profile, params.ProfileName, "schedulerName")
err = unstructured.SetNestedField(profile, params.ProfileName, "schedulerName")
if err != nil {
klog.ErrorS(err, "failed to update unstructured data", "schedulerName", params.ProfileName)
return data, false, err
}
updated = true
}

Expand Down