Skip to content

Commit

Permalink
fix: lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Apr 1, 2024
1 parent 9e4b75f commit 747c52c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 8 additions & 6 deletions checks/kubernetes_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,36 @@ func (c *KubernetesResourceChecker) Run(ctx *context.Context) pkg.Results {
return results
}

func (c *KubernetesResourceChecker) applyKubeconfig(ctx *context.Context, kubeConfig types.EnvVar) error {
func (c *KubernetesResourceChecker) applyKubeconfig(ctx *context.Context, kubeConfig types.EnvVar) (*context.Context, error) {
val, err := ctx.GetEnvValueFromCache(kubeConfig)
if err != nil {
return fmt.Errorf("failed to get kubeconfig from env: %w", err)
return nil, fmt.Errorf("failed to get kubeconfig from env: %w", err)
}

if strings.HasPrefix(val, "/") {
kClient, kube, err := pkg.NewKommonsClientWithConfigPath(val)
if err != nil {
return fmt.Errorf("failed to initialize kubernetes client from the provided kubeconfig: %w", err)
return nil, fmt.Errorf("failed to initialize kubernetes client from the provided kubeconfig: %w", err)
}

ctx = ctx.WithDutyContext(ctx.WithKommons(kClient))
ctx = ctx.WithDutyContext(ctx.WithKubernetes(kube))
} else {
kClient, kube, err := pkg.NewKommonsClientWithConfig(val)
if err != nil {
return fmt.Errorf("failed to initialize kubernetes client from the provided kubeconfig: %w", err)
return nil, fmt.Errorf("failed to initialize kubernetes client from the provided kubeconfig: %w", err)
}

ctx = ctx.WithDutyContext(ctx.WithKommons(kClient))
ctx = ctx.WithDutyContext(ctx.WithKubernetes(kube))
}

return nil
return ctx, nil
}

func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.KubernetesResourceCheck) pkg.Results {
result := pkg.Success(check, ctx.Canary)
var err error
var results pkg.Results
results = append(results, result)

Expand All @@ -92,7 +93,8 @@ func (c *KubernetesResourceChecker) Check(ctx *context.Context, check v1.Kuberne
}

if check.Kubeconfig != nil {
if err := c.applyKubeconfig(ctx, *check.Kubeconfig); err != nil {
ctx, err = c.applyKubeconfig(ctx, *check.Kubeconfig)
if err != nil {
return results.Failf("failed to apply kube config: %v", err)
}
}
Expand Down
5 changes: 5 additions & 0 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4986,6 +4986,11 @@ spec:
checks:
description: Checks to run against the kubernetes resources.
items:
description: |-
KubernetesResourceChecks is the canary spec.
NOTE: It's only created to make crd generation possible.
embedding CanarySpec into KubernetesResourceCheck.checks
directly generates an invalid crd.
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
Expand Down
5 changes: 5 additions & 0 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4985,6 +4985,11 @@ spec:
checks:
description: Checks to run against the kubernetes resources.
items:
description: |-
KubernetesResourceChecks is the canary spec.
NOTE: It's only created to make crd generation possible.
embedding CanarySpec into KubernetesResourceCheck.checks
directly generates an invalid crd.
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
Expand Down

0 comments on commit 747c52c

Please sign in to comment.