Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
voigt committed Feb 3, 2024
1 parent 02b15c1 commit b31cfd7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 86 deletions.
26 changes: 11 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,14 @@ issues:
# Disable 'funlen' linter for test functions.
# It's common for table-driven tests to be more than 60 characters long
source: "^func Test"
- path: internal/pkg/admission/policy-server-error.go
- path: '(.+)_test\.go'
linters:
- deadcode
- unused
- path: internal/pkg/admissionregistration/cert.go
- revive
text: "dot-imports: should not use dot imports"
- path: internal/controller/shim_controller.go
linters:
- gocritic
- path: internal/pkg/admission/validating-webhook.go
linters:
- dupl
- path: internal/pkg/admission/mutating-webhook.go
linters:
- dupl
- path: pkg/apis/policies/v1alpha2/clusteradmissionpolicy_types.go
text: "got 'TypeMeta' want 'typeMeta'"
- path: pkg/apis/policies/v1alpha2/policyserver_types.go
text: "got 'TypeMeta' want 'typeMeta'"
- unparam
source: "ctrl.Result"

linters:
enable-all: true
Expand Down Expand Up @@ -60,6 +51,11 @@ linters:
- ifshort # deprecated

linters-settings:
wrapcheck:
ignoreSigs:
- ".Complete("
- "client.IgnoreNotFound("
- "fmt.Errorf("
cyclop:
max-complexity: 13
nestif:
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/shim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ type ShimSpec struct {

type FetchStrategy struct {
Type string `json:"type"`
AnonHttp AnonHttpSpec `json:"anonHttp"`
AnonHTTP AnonHTTPSpec `json:"anonHttp"`
}

type AnonHttpSpec struct {
type AnonHTTPSpec struct {
Location string `json:"location"`
}

Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"flag"
"fmt"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -51,20 +50,6 @@ func init() {
//+kubebuilder:scaffold:scheme
}

// getWatchNamespace returns the Namespace the operator should be watching for changes
func getWatchNamespace() string {
// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
// which specifies the Namespace to watch.
// An empty value means the operator will fail to start.
watchNamespaceEnvVar := " "

ns, found := os.LookupEnv(watchNamespaceEnvVar)
if !found {
panic(fmt.Sprintf("env var '%s' must be set", watchNamespaceEnvVar))
}
return ns
}

func main() {
var metricsAddr string
var enableLeaderElection bool
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,34 @@ func (jr *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.

shimName := job.Labels["kwasm.sh/shimName"]

node, err := jr.getNode(ctx, job.Spec.Template.Spec.NodeName, req)
node, err := jr.getNode(ctx, job.Spec.Template.Spec.NodeName)
if err != nil {
return ctrl.Result{}, nil
return ctrl.Result{}, err
}

_, finishedType := jr.isJobFinished(job)
switch finishedType {
case "": // ongoing
log.Info().Msgf("Job %s is still Ongoing", job.Name)
// if err := jr.updateNodeLabels(ctx, node, shimName, "pending", req); err != nil {
// 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)
if err := jr.updateNodeLabels(ctx, node, shimName, "failed", req); err != nil {
if err := jr.updateNodeLabels(ctx, node, shimName, "failed"); err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shimName, err)
}
return ctrl.Result{}, nil
case batchv1.JobFailureTarget:
log.Info().Msgf("Job %s is about to fail", job.Name)
if err := jr.updateNodeLabels(ctx, node, shimName, "failed", req); err != nil {
if err := jr.updateNodeLabels(ctx, node, shimName, "failed"); err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shimName, err)
}
return ctrl.Result{}, nil
case batchv1.JobComplete:
log.Info().Msgf("Job %s is Completed. Happy WASMing", job.Name)
if err := jr.updateNodeLabels(ctx, node, shimName, "provisioned", req); err != nil {
if err := jr.updateNodeLabels(ctx, node, shimName, "provisioned"); err != nil {
log.Error().Msgf("Unable to update node label %s: %s", shimName, err)
}
return ctrl.Result{}, nil
Expand All @@ -119,17 +119,17 @@ func (jr *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return ctrl.Result{}, nil
}

func (jr *JobReconciler) updateNodeLabels(ctx context.Context, node *corev1.Node, shimName string, status string, req ctrl.Request) error {
func (jr *JobReconciler) updateNodeLabels(ctx context.Context, node *corev1.Node, shimName string, status string) error {
node.Labels[shimName] = status

if err := jr.Update(ctx, node); err != nil {
return err
return fmt.Errorf("failed to update node labels: %w", err)
}

return nil
}

func (jr *JobReconciler) getNode(ctx context.Context, nodeName string, req ctrl.Request) (*corev1.Node, error) {
func (jr *JobReconciler) getNode(ctx context.Context, nodeName string) (*corev1.Node, error) {
node := corev1.Node{}
if err := jr.Client.Get(ctx, types.NamespacedName{Name: nodeName}, &node); err != nil {
log.Err(err).Msg("Unable to fetch node")
Expand Down
Loading

0 comments on commit b31cfd7

Please sign in to comment.