Skip to content

Commit

Permalink
fix #329 add validation for ImagePullPolicy to prevent fallback to de…
Browse files Browse the repository at this point in the history
…fault for invalid options
  • Loading branch information
jim.sj committed Dec 12, 2024
1 parent f5d892b commit 49d0268
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pkg/skoop/collector/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ func NewSimplePodCollectorManager(ctx *ctx.Context) (collector.Manager, error) {
Config.SimplePodCollectorConfig.WaitTimeout = defaultWaitTimeout * time.Second
}

pullPolicy, err := utils.ConvertToImagePullPolicy(Config.SimplePodCollectorConfig.ImagePullPolicy)
if err != nil {
return nil, fmt.Errorf("failed to create pod collector manager: %w", err)
}

return &simplePodCollectorManager{
image: Config.SimplePodCollectorConfig.Image,
imagePullPolicy: utils.ConvertToImagePullPolicy(Config.SimplePodCollectorConfig.ImagePullPolicy),
imagePullPolicy: pullPolicy,
namespace: Config.SimplePodCollectorConfig.CollectorNamespace,
client: ctx.KubernetesClient(),
restConfig: ctx.KubernetesRestClient(),
Expand Down
6 changes: 3 additions & 3 deletions pkg/skoop/utils/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ func ContainsLoadBalancerIP(svc *v1.Service, ip string) bool {
return false
}

func ConvertToImagePullPolicy(policy string) v1.PullPolicy {
func ConvertToImagePullPolicy(policy string) (v1.PullPolicy, error) {
policyMap := map[string]v1.PullPolicy{
"Always": v1.PullAlways,
"IfNotPresent": v1.PullIfNotPresent,
"Never": v1.PullNever,
}

if pullPolicy, exists := policyMap[policy]; exists {
return pullPolicy
return pullPolicy, nil
}
return v1.PullAlways
return "", fmt.Errorf("invalid image pull policy: %s, valid options are: Always, IfNotPresent, Never", policy)
}

0 comments on commit 49d0268

Please sign in to comment.