Skip to content

Commit

Permalink
Enable to add Service Account Name in Katib config (#1092)
Browse files Browse the repository at this point in the history
* Enable to add service account name to katib config

* Fix test
  • Loading branch information
andreyvelich authored Mar 23, 2020
1 parent 11c832d commit 25cdf1c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/controller.v1alpha3/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const (
DefaultDiskRequest = "500Mi"
// LabelSuggestionImagePullPolicy is the name of suggestion image pull policy in configmap.
LabelSuggestionImagePullPolicy = "imagePullPolicy"
// LabelSuggestionServiceAccountName is the name of suggestion service account in configmap.
LabelSuggestionServiceAccountName = "serviceAccountName"
// DefaultImagePullPolicy is the default value for image pull policy.
DefaultImagePullPolicy = "IfNotPresent"
// LabelMetricsCollectorSidecar is the name of metrics collector config in configmap.
Expand Down
20 changes: 14 additions & 6 deletions pkg/controller.v1alpha3/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ func New(mgr manager.Manager) Composer {
}

func (g *General) DesiredDeployment(s *suggestionsv1alpha3.Suggestion) (*appsv1.Deployment, error) {
container, err := g.desiredContainer(s)

suggestionConfigData, err := katibconfig.GetSuggestionConfigData(s.Spec.AlgorithmName, g.Client)
if err != nil {
return nil, err
}

container, err := g.desiredContainer(s, suggestionConfigData)
if err != nil {
log.Error(err, "Error in constructing container")
return nil, err
Expand Down Expand Up @@ -82,6 +88,11 @@ func (g *General) DesiredDeployment(s *suggestionsv1alpha3.Suggestion) (*appsv1.
},
}

// Get Suggestion Service Account Name from config
if suggestionConfigData[consts.LabelSuggestionServiceAccountName] != "" {
d.Spec.Template.Spec.ServiceAccountName = suggestionConfigData[consts.LabelSuggestionServiceAccountName]
}

if err := controllerutil.SetControllerReference(s, d, g.scheme); err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,11 +127,8 @@ func (g *General) DesiredService(s *suggestionsv1alpha3.Suggestion) (*corev1.Ser
return service, nil
}

func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion) (*corev1.Container, error) {
suggestionConfigData, err := katibconfig.GetSuggestionConfigData(s.Spec.AlgorithmName, g.Client)
if err != nil {
return nil, err
}
func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion, suggestionConfigData map[string]string) (*corev1.Container, error) {

// Get Suggestion data from config
suggestionContainerImage := suggestionConfigData[consts.LabelSuggestionImageTag]
suggestionImagePullPolicy := suggestionConfigData[consts.LabelSuggestionImagePullPolicy]
Expand Down
13 changes: 10 additions & 3 deletions pkg/util/v1alpha3/katibconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
)

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

type metricsCollectorConfigJSON struct {
Expand Down Expand Up @@ -60,6 +61,12 @@ func GetSuggestionConfigData(algorithmName string, client client.Client) (map[st
suggestionConfigData[consts.LabelSuggestionImagePullPolicy] = consts.DefaultImagePullPolicy
}

// Get Service Account Name
serviceAccountName := suggestionConfig.ServiceAccountName
if strings.TrimSpace(serviceAccountName) != "" {
suggestionConfigData[consts.LabelSuggestionServiceAccountName] = serviceAccountName
}

// Set default values for CPU, Memory and Disk
suggestionConfigData[consts.LabelSuggestionCPURequestTag] = consts.DefaultCPURequest
suggestionConfigData[consts.LabelSuggestionMemRequestTag] = consts.DefaultMemRequest
Expand Down

0 comments on commit 25cdf1c

Please sign in to comment.