Skip to content

Commit

Permalink
Add UpsertCommand for Upsercontainer func (#580)
Browse files Browse the repository at this point in the history
Signed-off-by: raihankhan <raihan@appscode.com>
  • Loading branch information
raihankhan committed Feb 27, 2024
1 parent e0c1952 commit 1a60d17
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/v1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func UpsertContainer(containers []core.Container, upsert core.Container) []core.
}

func MergeContainer(container core.Container, containerTemplate core.Container) core.Container {
container.Command = containerTemplate.Command
container.Command = UpsertCommand(container.Command, containerTemplate.Command)
container.Args = meta.UpsertArgumentList(container.Args, containerTemplate.Args)
container.WorkingDir = containerTemplate.WorkingDir
container.EnvFrom = containerTemplate.EnvFrom
Expand Down Expand Up @@ -352,6 +352,22 @@ func EnsureEnvVarDeleted(vars []core.EnvVar, name string) []core.EnvVar {
return vars
}

func UpsertCommand(commands []string, nc []string) []string {
upsert := func(newCommand string) {
for _, c := range commands {
if c == newCommand {
return
}
}
commands = append(commands, newCommand)
}

for _, command := range nc {
upsert(command)
}
return commands
}

func MergeLocalObjectReferences(l1, l2 []core.LocalObjectReference) []core.LocalObjectReference {
result := make([]core.LocalObjectReference, 0, len(l1)+len(l2))
m := make(map[string]core.LocalObjectReference)
Expand Down

0 comments on commit 1a60d17

Please sign in to comment.