...

Source file src/github.com/redhat-developer/odo/pkg/testingutil/deployments.go

Documentation: github.com/redhat-developer/odo/pkg/testingutil

     1  package testingutil
     2  
     3  import (
     4  	appsv1 "k8s.io/api/apps/v1"
     5  	corev1 "k8s.io/api/core/v1"
     6  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     7  	"k8s.io/apimachinery/pkg/types"
     8  
     9  	odolabels "github.com/redhat-developer/odo/pkg/labels"
    10  )
    11  
    12  // CreateFakeDeployment creates a fake deployment with the given pod name and labels
    13  // isPartOfComponent bool decides if the deployment is supposed to be a part of the core resources deployed by `odo dev`
    14  func CreateFakeDeployment(podName string, isPartOfComponent bool) *appsv1.Deployment {
    15  	fakeUID := types.UID("12345")
    16  	labels := odolabels.Builder().
    17  		WithApp("app").
    18  		WithAppName("app").
    19  		WithComponentName(podName).
    20  		WithManager("odo").
    21  		WithMode(odolabels.ComponentDevMode)
    22  	if isPartOfComponent {
    23  		labels = labels.WithComponent(podName)
    24  	}
    25  	deployment := appsv1.Deployment{
    26  		TypeMeta: metav1.TypeMeta{
    27  			Kind:       "Deployment",
    28  			APIVersion: "apps/v1",
    29  		},
    30  		ObjectMeta: metav1.ObjectMeta{
    31  			Name:        podName,
    32  			UID:         fakeUID,
    33  			Labels:      labels.Labels(),
    34  			Annotations: odolabels.Builder().WithProjectType(podName).Labels(),
    35  		},
    36  	}
    37  	return &deployment
    38  }
    39  
    40  // CreateFakeDeploymentsWithContainers creates a fake pod with the given pod name, container name and containers
    41  // isPartOfComponent bool decides if the deployment is supposed to be a part of the core resources deployed by `odo dev`
    42  func CreateFakeDeploymentsWithContainers(podName string, containers []corev1.Container, initContainers []corev1.Container, isPartOfComponent bool) *appsv1.Deployment {
    43  	fakeDeployment := CreateFakeDeployment(podName, isPartOfComponent)
    44  	fakeDeployment.Spec.Template.Spec.Containers = containers
    45  	fakeDeployment.Spec.Template.Spec.InitContainers = initContainers
    46  	return fakeDeployment
    47  }
    48  

View as plain text