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

fix #329 : Add configurability to ImagePullPolicy to support offline environments by allowing IfNotPresent option. #330

Merged
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
2 changes: 2 additions & 0 deletions pkg/skoop/collector/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func init() {

type SimplePodCollectorConfig struct {
Image string
ImagePullPolicy string
CollectorNamespace string
RuntimeAPIAddress string
WaitInterval time.Duration
Expand All @@ -29,6 +30,7 @@ type SimplePodCollectorConfig struct {

func (cc *SimplePodCollectorConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringVarP(&cc.Image, "collector-image", "", "kubeskoop/agent:v1.0.0", "Image used for collector.")
fs.StringVarP(&cc.ImagePullPolicy, "collector-image-pull-policy", "", "Always", "The image pull policy for collector.")
fs.StringVarP(&cc.CollectorNamespace, "collector-namespace", "", "skoop", "Namespace where collector pods in.")
fs.StringVarP(&cc.RuntimeAPIAddress, "collector-cri-address", "", "", "Runtime CRI API endpoint address.")
fs.DurationVarP(&cc.WaitInterval, "collector-pod-wait-interval", "", 2*time.Second, "Collector pod running check interval.")
Expand Down
14 changes: 11 additions & 3 deletions pkg/skoop/collector/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type SimplePodCollectorManagerOptions struct {

type simplePodCollectorManager struct {
image string
imagePullPolicy v1.PullPolicy
namespace string
runtimeAPIAddress string
client *kubernetes.Clientset
Expand Down Expand Up @@ -75,8 +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: pullPolicy,
namespace: Config.SimplePodCollectorConfig.CollectorNamespace,
client: ctx.KubernetesClient(),
restConfig: ctx.KubernetesRestClient(),
Expand Down Expand Up @@ -332,7 +339,7 @@ func (m *simplePodCollectorManager) createCollectorPod(nodeName string) (*v1.Pod
{
Name: "collector",
Image: m.image,
ImagePullPolicy: "Always",
ImagePullPolicy: m.imagePullPolicy,
SecurityContext: &v1.SecurityContext{
Privileged: pointer.Bool(true),
},
Expand All @@ -359,8 +366,9 @@ func (m *simplePodCollectorManager) createCollectorPod(nodeName string) (*v1.Pod
},
Containers: []v1.Container{
{
Name: "alive",
Image: m.image,
Name: "alive",
Image: m.image,
ImagePullPolicy: m.imagePullPolicy,
Command: []string{
"/bin/sh",
"-c",
Expand Down
13 changes: 13 additions & 0 deletions pkg/skoop/utils/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ func ContainsLoadBalancerIP(svc *v1.Service, ip string) bool {
}
return false
}

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, nil
}
return "", fmt.Errorf("invalid image pull policy: %s, valid options are: Always, IfNotPresent, Never", policy)
}
Loading