Skip to content

Commit

Permalink
fix: check if node selector is disabled during pod build
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurcgc committed May 21, 2021
1 parent 84166b4 commit e6a7302
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -112,6 +112,7 @@ generate-test-certs:
cp ./app/testdata/private.key ./api/testdata/key.pem
cp ./app/testdata/certificate.crt ./api/testdata/cert.pem

# reference for minikube macOS registry: https://minikube.sigs.k8s.io/docs/handbook/registry/#docker-on-macos
development-mac:
minikube start --driver=virtualbox
minikube addons enable registry
Expand Down
33 changes: 23 additions & 10 deletions provision/kubernetes/deploy.go
Expand Up @@ -519,6 +519,18 @@ func ensureServiceAccountForApp(ctx context.Context, client *ClusterClient, a pr
return ensureServiceAccount(ctx, client, serviceAccountNameForApp(a), labels, ns)
}

func getClusterNodeSelectorFlag(client *ClusterClient) (bool, error) {
shouldDisable := false
if val, ok := client.GetCluster().CustomData[disableDefaultNodeSelectorKey]; ok {
var err error
shouldDisable, err = strconv.ParseBool(val)
if err != nil {
return false, errors.WithMessage(err, fmt.Sprintf("error while parsing cluster custom data entry: %s", disableDefaultNodeSelectorKey))
}
}
return shouldDisable, nil
}

func defineSelectorAndAffinity(ctx context.Context, a provision.App, client *ClusterClient) (map[string]string, *apiv1.Affinity, error) {
singlePool, err := client.SinglePool()
if err != nil {
Expand All @@ -540,15 +552,12 @@ func defineSelectorAndAffinity(ctx context.Context, a provision.App, client *Clu
return nil, affinity, nil
}

if val, ok := client.GetCluster().CustomData[disableDefaultNodeSelectorKey]; ok {
var shouldDisable bool
shouldDisable, err = strconv.ParseBool(val)
if err != nil {
return nil, nil, errors.WithMessage(err, fmt.Sprintf("error while parsing cluster custom data entry: %s", disableDefaultNodeSelectorKey))
}
if shouldDisable {
return nil, affinity, nil
}
shouldDisable, err := getClusterNodeSelectorFlag(client)
if err != nil {
return nil, nil, err
}
if shouldDisable {
return nil, affinity, nil
}

return provision.NodeLabels(provision.NodeLabelsOpts{
Expand Down Expand Up @@ -1813,7 +1822,11 @@ func newDeployAgentImageBuildPod(ctx context.Context, client *ClusterClient, sou
if err != nil {
return apiv1.Pod{}, errors.WithMessage(err, "misconfigured cluster single pool value")
}
if singlePool {
shouldDisable, err := getClusterNodeSelectorFlag(client)
if err != nil {
return apiv1.Pod{}, err
}
if shouldDisable || singlePool {
affinity = &apiv1.Affinity{}
}
_, uid := dockercommon.UserForContainer()
Expand Down

0 comments on commit e6a7302

Please sign in to comment.