Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
voigt committed Feb 14, 2024
1 parent bb21cdc commit b03b7fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ linters-settings:
- "client.IgnoreNotFound("
- "fmt.Errorf("
cyclop:
max-complexity: 13
max-complexity: 16
nestif:
min-complexity: 8
depguard:
Expand Down
11 changes: 5 additions & 6 deletions internal/controller/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func (jr *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
switch finishedType {
case "": // ongoing
log.Info().Msgf("Job %s is still Ongoing", job.Name)
// if err := jr.updateNodeLabels(ctx, node, shimName, "pending"); err != nil {
// log.Error().Msgf("Unable to update node label %s: %s", shimName, err)
// }
return ctrl.Result{}, nil
case batchv1.JobFailed:
log.Info().Msgf("Job %s is still failing...", job.Name)
Expand All @@ -111,12 +108,14 @@ func (jr *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
installOrUninstall := job.Annotations["kwasm.sh/operation"]

switch installOrUninstall {
case "install":
case INSTALL:
if err := jr.updateNodeLabels(ctx, node, shimName, "provisioned"); err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shimName, err)
}
case "uninstall":
jr.deleteNodeLabel(ctx, node, shimName)
case UNINSTALL:
if err := jr.deleteNodeLabel(ctx, node, shimName); err != nil {
log.Error().Msgf("Unable to delete node label %s: %s", shimName, err)
}
}

return ctrl.Result{}, err
Expand Down
18 changes: 10 additions & 8 deletions internal/controller/shim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (

const (
KwasmOperatorFinalizer = "kwasm.sh/finalizer"
INSTALL = "install"
UNINSTALL = "uninstall"
)

// ShimReconciler reconciles a Shim object
Expand Down Expand Up @@ -220,7 +222,7 @@ func (sr *ShimReconciler) handleInstallShim(ctx context.Context, shim *kwasmv1.S
shimProvisioned := node.Labels[shim.Name] == "provisioned"
shimPending := node.Labels[shim.Name] == "pending"
if !shimProvisioned && !shimPending {
err := sr.deployJobOnNode(ctx, shim, node, "install")
err := sr.deployJobOnNode(ctx, shim, node, INSTALL)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -252,23 +254,23 @@ func (sr *ShimReconciler) deployJobOnNode(ctx context.Context, shim *kwasmv1.Shi
var job *batchv1.Job

switch jobType {
case "install":
case INSTALL:
err := sr.updateNodeLabels(ctx, &node, shim, "pending")
if err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shim.Name, err)
}

job, err = sr.createJobManifest(shim, &node, "install")
job, err = sr.createJobManifest(shim, &node, INSTALL)
if err != nil {
return err
}
case "uninstall":
err := sr.updateNodeLabels(ctx, &node, shim, "uninstall")
case UNINSTALL:
err := sr.updateNodeLabels(ctx, &node, shim, UNINSTALL)
if err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shim.Name, err)
}

job, err = sr.createJobManifest(shim, &node, "uninstall")
job, err = sr.createJobManifest(shim, &node, UNINSTALL)
if err != nil {
return err
}
Expand Down Expand Up @@ -385,7 +387,7 @@ func (sr *ShimReconciler) createJobManifest(shim *kwasmv1.Shim, node *corev1.Nod
},
}

if operation == "install" {
if operation == INSTALL {
if err := ctrl.SetControllerReference(shim, job, sr.Scheme); err != nil {
return nil, fmt.Errorf("failed to set controller reference: %w", err)
}
Expand Down Expand Up @@ -460,7 +462,7 @@ func (sr *ShimReconciler) handleDeleteShim(ctx context.Context, shim *kwasmv1.Sh
node := nodes.Items[i]

if _, exists := node.Labels[shim.Name]; exists {
err := sr.deployJobOnNode(ctx, shim, node, "uninstall")
err := sr.deployJobOnNode(ctx, shim, node, UNINSTALL)
if client.IgnoreNotFound(err) != nil {
return err
}
Expand Down

0 comments on commit b03b7fa

Please sign in to comment.