Skip to content

Commit

Permalink
handle serviceAccountName the same as other fields
Browse files Browse the repository at this point in the history
input fields are defaulted on the config object in the init function,
rather than derived via accessors
  • Loading branch information
ecordell committed Jan 9, 2023
1 parent c2fedd3 commit 13c6abd
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 126 deletions.
17 changes: 8 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/fatih/camelcase"
"github.com/jzelinskie/stringz"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -199,6 +198,10 @@ func NewConfig(nn types.NamespacedName, uid types.UID, version, channel string,
migrationConfig.TargetMigration = Head
}

if len(spiceConfig.ServiceAccountName) == 0 {
spiceConfig.ServiceAccountName = nn.Name
}

switch {
case len(state.Digest) > 0:
migrationConfig.TargetSpiceDBImage = baseImage + "@" + state.Digest
Expand Down Expand Up @@ -394,12 +397,8 @@ func (c *Config) OwnerRef() *applymetav1.OwnerReferenceApplyConfiguration {
WithUID(types.UID(c.UID))
}

func (c *Config) GetServiceAccountName() string {
return stringz.DefaultEmpty(c.ServiceAccountName, c.Name)
}

func (c *Config) ServiceAccount() *applycorev1.ServiceAccountApplyConfiguration {
return applycorev1.ServiceAccount(c.GetServiceAccountName(), c.Namespace).
return applycorev1.ServiceAccount(c.ServiceAccountName, c.Namespace).
WithLabels(metadata.LabelsForComponent(c.Name, metadata.ComponentServiceAccountLabel)).
WithAnnotations(c.ExtraServiceAccountAnnotations).
WithOwnerReferences(c.OwnerRef())
Expand All @@ -426,7 +425,7 @@ func (c *Config) RoleBinding() *applyrbacv1.RoleBindingApplyConfiguration {
WithName(c.Name),
).WithSubjects(applyrbacv1.Subject().
WithNamespace(c.Namespace).
WithKind("ServiceAccount").WithName(c.GetServiceAccountName()),
WithKind("ServiceAccount").WithName(c.ServiceAccountName),
)
}

Expand Down Expand Up @@ -504,7 +503,7 @@ func (c *Config) MigrationJob(migrationHash string) *applybatchv1.JobApplyConfig
WithSpec(applybatchv1.JobSpec().WithTemplate(
applycorev1.PodTemplateSpec().WithLabels(
metadata.LabelsForComponent(c.Name, metadata.ComponentMigrationJobLabelValue),
).WithSpec(applycorev1.PodSpec().WithServiceAccountName(c.GetServiceAccountName()).
).WithSpec(applycorev1.PodSpec().WithServiceAccountName(c.ServiceAccountName).
WithContainers(
applycorev1.Container().
WithName(name).
Expand Down Expand Up @@ -593,7 +592,7 @@ func (c *Config) Deployment(migrationHash, secretHash string) *applyappsv1.Deplo
WithLabels(metadata.LabelsForComponent(c.Name, metadata.ComponentSpiceDBLabelValue)).
WithLabels(c.ExtraPodLabels).
WithAnnotations(c.ExtraPodAnnotations).
WithSpec(applycorev1.PodSpec().WithServiceAccountName(c.GetServiceAccountName()).WithContainers(
WithSpec(applycorev1.PodSpec().WithServiceAccountName(c.ServiceAccountName).WithContainers(
applycorev1.Container().WithName(name).WithImage(c.TargetSpiceDBImage).
WithCommand(c.SpiceConfig.SpiceDBCmd, "serve").
WithEnv(c.ToEnvVarApplyConfiguration()...).
Expand Down
Loading

0 comments on commit 13c6abd

Please sign in to comment.