From afd9f45bc59e0ad72cdc7c437254939bc05fa35a Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Mon, 20 Feb 2023 13:15:56 +0100 Subject: [PATCH] Add GetPodTemplateSpec to build the complete PodTemplateSpec (to replace calls to GetContainers + GetInitContainers) Signed-off-by: Philippe Martin --- pkg/devfile/generator/generators.go | 52 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/pkg/devfile/generator/generators.go b/pkg/devfile/generator/generators.go index 42d6cd8c..fea75098 100644 --- a/pkg/devfile/generator/generators.go +++ b/pkg/devfile/generator/generators.go @@ -168,25 +168,24 @@ func GetInitContainers(devfileObj parser.DevfileObj) ([]corev1.Container, error) return initContainers, nil } -// DeploymentParams is a struct that contains the required data to create a deployment object -type DeploymentParams struct { - TypeMeta metav1.TypeMeta - ObjectMeta metav1.ObjectMeta - InitContainers []corev1.Container - Containers []corev1.Container - Volumes []corev1.Volume - PodSelectorLabels map[string]string - Replicas *int32 +// PodTemplateParams is a struct that contains the required data to create a podtemplatespec object +type PodTemplateParams struct { + ObjectMeta metav1.ObjectMeta } -// GetDeployment gets a deployment object -func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams) (*appsv1.Deployment, error) { - +func GetPodTemplateSpec(devfileObj parser.DevfileObj, podTemplateParams PodTemplateParams) (*corev1.PodTemplateSpec, error) { + containers, err := GetContainers(devfileObj, common.DevfileOptions{}) + if err != nil { + return nil, err + } + initContainers, err := GetInitContainers(devfileObj) + if err != nil { + return nil, err + } podTemplateSpecParams := podTemplateSpecParams{ - ObjectMeta: deployParams.ObjectMeta, - InitContainers: deployParams.InitContainers, - Containers: deployParams.Containers, - Volumes: deployParams.Volumes, + ObjectMeta: podTemplateParams.ObjectMeta, + InitContainers: initContainers, + Containers: containers, } var globalAttributes attributes.Attributes // attributes is not supported in versions less than 2.1.0, so we skip it @@ -199,12 +198,23 @@ func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams) if err != nil { return nil, err } - podTemplateSpec, err := getPodTemplateSpec(globalAttributes, components, podTemplateSpecParams) - if err != nil { - return nil, err - } + return getPodTemplateSpec(globalAttributes, components, podTemplateSpecParams) +} + +// DeploymentParams is a struct that contains the required data to create a deployment object +type DeploymentParams struct { + TypeMeta metav1.TypeMeta + ObjectMeta metav1.ObjectMeta + PodTemplateSpec *corev1.PodTemplateSpec + PodSelectorLabels map[string]string + Replicas *int32 +} + +// GetDeployment gets a deployment object +func GetDeployment(devfileObj parser.DevfileObj, deployParams DeploymentParams) (*appsv1.Deployment, error) { + deploySpecParams := deploymentSpecParams{ - PodTemplateSpec: *podTemplateSpec, + PodTemplateSpec: *deployParams.PodTemplateSpec, PodSelectorLabels: deployParams.PodSelectorLabels, Replicas: deployParams.Replicas, }