Skip to content

Commit

Permalink
Enable imagePullPolicy from katib-config (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyvelich authored and k8s-ci-robot committed Jan 15, 2020
1 parent 489d52b commit 96df045
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions manifests/v1alpha3/katib-controller/katib-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data:
},
"nasrl": {
"image": "gcr.io/kubeflow-images-public/katib/v1alpha3/suggestion-nasrl",
"imagePullPolicy": "Always",
"resources": {
"limits": {
"memory": "200Mi"
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller.v1alpha3/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const (
LabelSuggestionDiskRequestTag = "diskRequest"
// DefaultDiskRequest is the default value for disk request.
DefaultDiskRequest = "500Mi"
// LabelSuggestionImagePullPolicy is the name of suggestion image pull policy in configmap.
LabelSuggestionImagePullPolicy = "imagePullPolicy"
// DefaultImagePullPolicy is the default value for image pull policy.
DefaultImagePullPolicy = "IfNotPresent"
// LabelMetricsCollectorSidecar is the name of metrics collector config in configmap.
LabelMetricsCollectorSidecar = "metrics-collector-sidecar"
// LabelMetricsCollectorSidecarImage is the name of metrics collector image config in configmap.
Expand All @@ -82,6 +86,8 @@ const (
LabelMetricsCollectorDiskLimitTag = "diskLimit"
// LabelMetricsCollectorDiskRequestTag is the name of metrics collector Disk Request config in configmap.
LabelMetricsCollectorDiskRequestTag = "diskRequest"
// LabelMetricsCollectorImagePullPolicy is the name of metrics collector image pull policy in configmap.
LabelMetricsCollectorImagePullPolicy = "imagePullPolicy"

// ReconcileErrorReason is the reason when there is a reconcile error.
ReconcileErrorReason = "ReconcileError"
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller.v1alpha3/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion) (*corev1.C
}
// Get Suggestion data from config
suggestionContainerImage := suggestionConfigData[consts.LabelSuggestionImageTag]
suggestionImagePullPolicy := suggestionConfigData[consts.LabelSuggestionImagePullPolicy]
suggestionCPULimit := suggestionConfigData[consts.LabelSuggestionCPULimitTag]
suggestionCPURequest := suggestionConfigData[consts.LabelSuggestionCPURequestTag]
suggestionMemLimit := suggestionConfigData[consts.LabelSuggestionMemLimitTag]
Expand All @@ -128,7 +129,7 @@ func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion) (*corev1.C
Name: consts.ContainerSuggestion,
}
c.Image = suggestionContainerImage
c.ImagePullPolicy = corev1.PullIfNotPresent
c.ImagePullPolicy = corev1.PullPolicy(suggestionImagePullPolicy)
c.Ports = []corev1.ContainerPort{
{
Name: consts.DefaultSuggestionPortName,
Expand Down
26 changes: 22 additions & 4 deletions pkg/util/v1alpha3/katibconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
)

type suggestionConfigJSON struct {
Image string `json:"image"`
Resource corev1.ResourceRequirements `json:"resources"`
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy"`
Resource corev1.ResourceRequirements `json:"resources"`
}

type metricsCollectorConfigJSON struct {
Image string `json:"image"`
Resource corev1.ResourceRequirements `json:"resources"`
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy"`
Resource corev1.ResourceRequirements `json:"resources"`
}

// GetSuggestionConfigData gets the config data for the given algorithm name.
Expand Down Expand Up @@ -50,6 +52,14 @@ func GetSuggestionConfigData(algorithmName string, client client.Client) (map[st
return map[string]string{}, errors.New("Required value for " + consts.LabelSuggestionImageTag + " configuration of algorithm name " + algorithmName)
}

// Get Image Pull Policy
imagePullPolicy := suggestionConfig.ImagePullPolicy
if imagePullPolicy == corev1.PullAlways || imagePullPolicy == corev1.PullIfNotPresent || imagePullPolicy == corev1.PullNever {
suggestionConfigData[consts.LabelSuggestionImagePullPolicy] = string(imagePullPolicy)
} else {
suggestionConfigData[consts.LabelSuggestionImagePullPolicy] = consts.DefaultImagePullPolicy
}

// Set default values for CPU, Memory and Disk
suggestionConfigData[consts.LabelSuggestionCPURequestTag] = consts.DefaultCPURequest
suggestionConfigData[consts.LabelSuggestionMemRequestTag] = consts.DefaultMemRequest
Expand Down Expand Up @@ -123,6 +133,14 @@ func GetMetricsCollectorConfigData(cKind common.CollectorKind, client client.Cli
return metricsCollectorConfigData, errors.New("Required value for " + consts.LabelMetricsCollectorSidecarImage + "configuration of metricsCollector kind " + kind)
}

// Get Image Pull Policy
imagePullPolicy := metricsCollectorConfig.ImagePullPolicy
if imagePullPolicy == corev1.PullAlways || imagePullPolicy == corev1.PullIfNotPresent || imagePullPolicy == corev1.PullNever {
metricsCollectorConfigData[consts.LabelMetricsCollectorImagePullPolicy] = string(imagePullPolicy)
} else {
metricsCollectorConfigData[consts.LabelMetricsCollectorImagePullPolicy] = consts.DefaultImagePullPolicy
}

// Set default values for CPU, Memory and Disk
metricsCollectorConfigData[consts.LabelMetricsCollectorCPURequestTag] = consts.DefaultCPURequest
metricsCollectorConfigData[consts.LabelMetricsCollectorMemRequestTag] = consts.DefaultMemRequest
Expand Down
3 changes: 2 additions & 1 deletion pkg/webhook/v1alpha3/pod/inject_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func (s *sidecarInjector) getMetricsCollectorContainer(trial *trialsv1alpha3.Tri

// Get metricsCollector data from config
metricsCollectorContainerImage := metricsCollectorConfigData[consts.LabelMetricsCollectorSidecarImage]
metricsCollectorImagePullPolicy := metricsCollectorConfigData[consts.LabelMetricsCollectorImagePullPolicy]
metricsCollectorCPULimit := metricsCollectorConfigData[consts.LabelMetricsCollectorCPULimitTag]
metricsCollectorCPURequest := metricsCollectorConfigData[consts.LabelMetricsCollectorCPURequestTag]
metricsCollectorMemLimit := metricsCollectorConfigData[consts.LabelMetricsCollectorMemLimitTag]
Expand Down Expand Up @@ -222,7 +223,7 @@ func (s *sidecarInjector) getMetricsCollectorContainer(trial *trialsv1alpha3.Tri
Name: sidecarContainerName,
Image: metricsCollectorContainerImage,
Args: args,
ImagePullPolicy: v1.PullIfNotPresent,
ImagePullPolicy: v1.PullPolicy(metricsCollectorImagePullPolicy),
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: cpuLimitQuantity,
Expand Down

0 comments on commit 96df045

Please sign in to comment.