fix: custom runtime container name is invalid (#3065)
* fix: custom runtime container name is invalid * lint: pkg/executor/executortype/newdeploy/newdeploy.go * Custom name for runtime container Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io> --------- Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io> Co-authored-by: Md Soharab Ansari <soharab.ansari@infracloud.io>
This commit is contained in:
co-authored by
Md Soharab Ansari
parent
0bbb5c5f38
commit
703613a475
@@ -281,10 +281,20 @@ func (deploy *NewDeploy) getDeploymentSpec(ctx context.Context, fn *fv1.Function
|
||||
},
|
||||
}
|
||||
|
||||
// If custom runtime container name - default env name
|
||||
mainContainerName := env.ObjectMeta.Name
|
||||
if env.Spec.Runtime.Container != nil && env.Spec.Runtime.Container.Name != "" && env.Spec.Runtime.PodSpec != nil {
|
||||
if util.DoesContainerExistInPodSpec(env.Spec.Runtime.Container.Name, env.Spec.Runtime.PodSpec) {
|
||||
mainContainerName = env.Spec.Runtime.Container.Name
|
||||
} else {
|
||||
return nil, fmt.Errorf("runtime container %s not found in pod spec", env.Spec.Runtime.Container.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Order of merging is important here - first fetcher, then containers and lastly pod spec
|
||||
err = deploy.fetcherConfig.AddSpecializingFetcherToPodSpec(
|
||||
&deployment.Spec.Template.Spec,
|
||||
env.ObjectMeta.Name,
|
||||
mainContainerName,
|
||||
fn,
|
||||
env,
|
||||
)
|
||||
|
||||
@@ -189,8 +189,18 @@ func (gp *GenericPool) genDeploymentSpec(env *fv1.Environment) (*appsv1.Deployme
|
||||
Template: pod,
|
||||
}
|
||||
|
||||
// If custom runtime container name - default env name
|
||||
mainContainerName := env.ObjectMeta.Name
|
||||
if env.Spec.Runtime.Container != nil && env.Spec.Runtime.Container.Name != "" && env.Spec.Runtime.PodSpec != nil {
|
||||
if util.DoesContainerExistInPodSpec(env.Spec.Runtime.Container.Name, env.Spec.Runtime.PodSpec) {
|
||||
mainContainerName = env.Spec.Runtime.Container.Name
|
||||
} else {
|
||||
return nil, fmt.Errorf("runtime container %s not found in pod spec", env.Spec.Runtime.Container.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Order of merging is important here - first fetcher, then containers and lastly pod spec
|
||||
err = gp.fetcherConfig.AddFetcherToPodSpec(&deploymentSpec.Template.Spec, env.ObjectMeta.Name)
|
||||
err = gp.fetcherConfig.AddFetcherToPodSpec(&deploymentSpec.Template.Spec, mainContainerName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -168,3 +168,13 @@ func CreateDumpFile(logger *zap.Logger) (*os.File, error) {
|
||||
|
||||
return os.Create(fmt.Sprintf("%s/%s-%d.txt", dumpPath, dumpFileName, time.Now().Unix()))
|
||||
}
|
||||
|
||||
// DoesContainerExistInPodSpec checks if the container with the given name exists in the pod spec
|
||||
func DoesContainerExistInPodSpec(containerName string, podSpec *apiv1.PodSpec) bool {
|
||||
for _, container := range podSpec.Containers {
|
||||
if container.Name == containerName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user