Skip to content

Commit

Permalink
Add GetPodTemplateSpec to build the complete PodTemplateSpec (to repl…
Browse files Browse the repository at this point in the history
…ace calls to GetContainers + GetInitContainers)

Signed-off-by: Philippe Martin <phmartin@redhat.com>
  • Loading branch information
feloy committed Feb 20, 2023
1 parent f9da760 commit afd9f45
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions pkg/devfile/generator/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
Expand Down

0 comments on commit afd9f45

Please sign in to comment.