Skip to content

Commit

Permalink
Add getter utilities for container, volume, volumeMount & env (#564)
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <arnob@appscode.com>
  • Loading branch information
ArnobKumarSaha authored Nov 9, 2023
1 parent 8acfc65 commit 59549ee
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions core/v1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func EnsureContainerDeleted(containers []core.Container, name string) []core.Con
return containers
}

func GetContainerByName(containers []core.Container, name string) *core.Container {
for i := range containers {
if containers[i].Name == name {
return &containers[i]
}
}
return nil
}

func UpsertContainer(containers []core.Container, upsert core.Container) []core.Container {
for i, container := range containers {
if container.Name == upsert.Name {
Expand Down Expand Up @@ -116,6 +125,15 @@ func DeleteContainer(containers []core.Container, name string) []core.Container
return containers
}

func GetVolumeByName(volumes []core.Volume, name string) *core.Volume {
for i := range volumes {
if volumes[i].Name == name {
return &volumes[i]
}
}
return nil
}

func UpsertVolume(volumes []core.Volume, nv ...core.Volume) []core.Volume {
upsert := func(v core.Volume) {
for i, vol := range volumes {
Expand Down Expand Up @@ -192,6 +210,15 @@ func EnsureVolumeDeleted(volumes []core.Volume, name string) []core.Volume {
return volumes
}

func GetVolumeMountByName(volumeMounts []core.VolumeMount, name string) *core.VolumeMount {
for i := range volumeMounts {
if volumeMounts[i].Name == name {
return &volumeMounts[i]
}
}
return nil
}

func UpsertVolumeMount(mounts []core.VolumeMount, nv ...core.VolumeMount) []core.VolumeMount {
upsert := func(m core.VolumeMount) {
for i, vol := range mounts {
Expand Down Expand Up @@ -237,6 +264,15 @@ func EnsureVolumeMountDeletedByPath(mounts []core.VolumeMount, mountPath string)
return mounts
}

func GetEnvByName(envs []core.EnvVar, name string) *core.EnvVar {
for i := range envs {
if envs[i].Name == name {
return &envs[i]
}
}
return nil
}

func UpsertEnvVars(vars []core.EnvVar, nv ...core.EnvVar) []core.EnvVar {
upsert := func(env core.EnvVar) {
if env.ValueFrom != nil &&
Expand Down

0 comments on commit 59549ee

Please sign in to comment.