diff --git a/pkg/component/component.go b/pkg/component/component.go index a0d0fca1cc3..3f7fd52fa35 100644 --- a/pkg/component/component.go +++ b/pkg/component/component.go @@ -16,10 +16,10 @@ import ( "github.com/devfile/library/pkg/devfile/parser" parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common" dfutil "github.com/devfile/library/pkg/util" + "github.com/redhat-developer/odo/pkg/devfile/location" applabels "github.com/redhat-developer/odo/pkg/application/labels" componentlabels "github.com/redhat-developer/odo/pkg/component/labels" - "github.com/redhat-developer/odo/pkg/devfile/location" "github.com/redhat-developer/odo/pkg/envinfo" "github.com/redhat-developer/odo/pkg/kclient" "github.com/redhat-developer/odo/pkg/libdevfile" @@ -42,7 +42,6 @@ const componentRandomNamePartsMaxLen = 12 const componentNameMaxRetries = 3 const componentNameMaxLen = -1 const NotAvailable = "Not available" - const apiVersion = "odo.dev/v1alpha1" // GetComponentDir returns source repo name @@ -141,7 +140,7 @@ func ListDevfileComponents(client kclient.ClientInterface, selector string) (Com // create a list of object metadata based on the component and application name (extracted from Deployment labels) for _, elem := range deploymentList { - component, err := GetComponent(client, elem.Labels[componentlabels.ComponentLabel], elem.Labels[applabels.ApplicationLabel], client.GetCurrentNamespace()) + component, err := GetComponent(client, elem.Labels[componentlabels.KubernetesInstanceLabel], elem.Labels[applabels.ApplicationLabel], client.GetCurrentNamespace()) if err != nil { return ComponentList{}, errors.Wrap(err, "Unable to get component") } @@ -231,6 +230,7 @@ func GetLanguageFromDevfileMetadata(metadata devfile.DevfileMetadata) string { func getComponentFrom(info localConfigProvider.LocalConfigProvider, componentType string) (Component, error) { if info.Exists() { + component := newComponentWithType(info.GetName(), componentType) component.Namespace = info.GetNamespace() @@ -328,8 +328,8 @@ func Exists(client kclient.ClientInterface, componentName, applicationName strin return false, nil } -func GetComponentState(client kclient.ClientInterface, componentName, applicationName string) State { - // first check if a deployment exists +func GetComponentState(client kclient.ClientInterface, componentName, applicationName string) string { + // Check to see if the deployment has been pushed or not c, err := GetPushedComponent(client, componentName, applicationName) if err != nil { return StateTypeUnknown @@ -413,13 +413,14 @@ func getRemoteComponentMetadata(client kclient.ClientInterface, componentName st // Annotations component.Annotations = fromCluster.GetAnnotations() + // Mark the component status as pushed + component.Status.State = StateTypePushed + // Labels component.Labels = fromCluster.GetLabels() - component.Namespace = client.GetCurrentNamespace() component.Spec.App = applicationName component.Spec.Env = filteredEnv - component.Status.State = StateTypePushed return component, nil } @@ -476,7 +477,7 @@ func setLinksServiceNames(client kclient.ClientInterface, linkedSecrets []Secret serviceCompMap := make(map[string]string) for _, gotService := range services { - serviceCompMap[gotService.Labels[componentlabels.ComponentLabel]] = gotService.Name + serviceCompMap[gotService.Labels[componentlabels.KubernetesInstanceLabel]] = gotService.Name } for _, secret := range secrets { diff --git a/pkg/component/component_full_description.go b/pkg/component/component_full_description.go index 519b5d3a453..a0d543fce20 100644 --- a/pkg/component/component_full_description.go +++ b/pkg/component/component_full_description.go @@ -74,7 +74,7 @@ func (cfd *ComponentFullDescription) fillEmptyFields(componentDesc Component, co // NewComponentFullDescriptionFromClientAndLocalConfigProvider gets the complete description of the component from cluster func NewComponentFullDescriptionFromClientAndLocalConfigProvider(client kclient.ClientInterface, envInfo *envinfo.EnvSpecificInfo, componentName string, applicationName string, projectName string, context string) (*ComponentFullDescription, error) { cfd := &ComponentFullDescription{} - var state State + var state string if client == nil { state = StateTypeUnknown } else { diff --git a/pkg/component/component_test.go b/pkg/component/component_test.go index 0b1df2fd9dc..aa7b00f28c0 100644 --- a/pkg/component/component_test.go +++ b/pkg/component/component_test.go @@ -7,6 +7,7 @@ import ( "testing" devfilepkg "github.com/devfile/api/v2/pkg/devfile" + "github.com/kylelemons/godebug/pretty" v1 "k8s.io/api/apps/v1" @@ -146,13 +147,13 @@ func TestList(t *testing.T) { *testingutil.CreateFakeDeployment("comp1"), }} - deploymentList.Items[0].Labels[componentlabels.ComponentTypeLabel] = "nodejs" + deploymentList.Items[0].Labels[componentlabels.KubernetesNameLabel] = "nodejs" deploymentList.Items[0].Annotations = map[string]string{ - componentlabels.ComponentTypeAnnotation: "nodejs", + componentlabels.OdoProjectTypeAnnotation: "nodejs", } - deploymentList.Items[1].Labels[componentlabels.ComponentTypeLabel] = "wildfly" + deploymentList.Items[1].Labels[componentlabels.KubernetesNameLabel] = "wildfly" deploymentList.Items[1].Annotations = map[string]string{ - componentlabels.ComponentTypeAnnotation: "wildfly", + componentlabels.OdoProjectTypeAnnotation: "wildfly", } tests := []struct { name string @@ -223,6 +224,7 @@ func TestList(t *testing.T) { } if !reflect.DeepEqual(tt.output, results) { + t.Errorf("Unexpected output, see the diff in results: %s", pretty.Compare(tt.output, results)) t.Errorf("expected output:\n%#v\n\ngot:\n%#v", tt.output, results) } }) @@ -472,7 +474,7 @@ func TestGetComponentTypeFromDevfileMetadata(t *testing.T) { } } -func getFakeComponent(compName, namespace, appName, compType string, state State) Component { +func getFakeComponent(compName, namespace, appName, compType string, state string) Component { return Component{ TypeMeta: metav1.TypeMeta{ Kind: "Component", @@ -482,14 +484,14 @@ func getFakeComponent(compName, namespace, appName, compType string, state State Name: compName, Namespace: namespace, Labels: map[string]string{ - applabels.App: appName, - applabels.ManagedBy: "odo", - applabels.ApplicationLabel: appName, - componentlabels.ComponentLabel: compName, - componentlabels.ComponentTypeLabel: compType, + applabels.App: appName, + applabels.ManagedBy: "odo", + applabels.ApplicationLabel: appName, + componentlabels.KubernetesInstanceLabel: compName, + componentlabels.KubernetesNameLabel: compType, }, Annotations: map[string]string{ - componentlabels.ComponentTypeAnnotation: compType, + componentlabels.OdoProjectTypeAnnotation: compType, }, }, Spec: ComponentSpec{ diff --git a/pkg/component/labels/labels.go b/pkg/component/labels/labels.go index 81bd4761ab5..877d0340c11 100644 --- a/pkg/component/labels/labels.go +++ b/pkg/component/labels/labels.go @@ -5,22 +5,26 @@ import ( "github.com/redhat-developer/odo/pkg/util" ) -// ComponentLabel is a label key used to identify the component name -const ComponentLabel = "app.kubernetes.io/instance" +// KubernetesInstanceLabel is a label key used to identify the component name +const KubernetesInstanceLabel = "app.kubernetes.io/instance" -// ComponentTypeLabel is Kubernetes label that identifies the type of a component being used -const ComponentTypeLabel = "app.kubernetes.io/name" +// KubernetesNameLabel is Kubernetes label that identifies the type of a component being used +const KubernetesNameLabel = "app.kubernetes.io/name" -const ComponentTypeAnnotation = "odo.dev/project-type" +// KubernetesManagedByLabel ... +const KubernetesManagedByLabel = "app.kubernetes.io/managed-by" -// ComponentDeployLabel ... -const ComponentDeployLabel = "Deploy" +// ComponentDevName ... +const ComponentDevName = "Dev" -// ComponentModeLabel ... -const ComponentModeLabel = "odo.dev/mode" +// ComponentDeployName ... +const ComponentDeployName = "Deploy" -// ComponentProjectTypeLabel ... -const ComponentProjectTypeLabel = "odo.dev/project-type" +// OdoModeLabel ... +const OdoModeLabel = "odo.dev/mode" + +// OdoProjectTypeAnnotation ... +const OdoProjectTypeAnnotation = "odo.dev/project-type" // GetLabels return labels that should be applied to every object for given component in active application // additional labels are used only for creating object @@ -28,7 +32,7 @@ const ComponentProjectTypeLabel = "odo.dev/project-type" // if you need labels to filter component then use additional=false func GetLabels(componentName string, applicationName string, additional bool) map[string]string { labels := applabels.GetLabels(applicationName, additional) - labels[ComponentLabel] = componentName + labels[KubernetesInstanceLabel] = componentName return labels } diff --git a/pkg/component/labels/labels_test.go b/pkg/component/labels/labels_test.go index 9d89ddb4470..4c75094e943 100644 --- a/pkg/component/labels/labels_test.go +++ b/pkg/component/labels/labels_test.go @@ -28,7 +28,7 @@ func TestGetLabels(t *testing.T) { }, want: map[string]string{ applabels.ApplicationLabel: "applicationame", - ComponentLabel: "componentname", + KubernetesInstanceLabel: "componentname", }, }, { name: "everything with additional", @@ -42,7 +42,7 @@ func TestGetLabels(t *testing.T) { applabels.App: "applicationame", applabels.ManagedBy: "odo", applabels.ManagerVersion: version.VERSION, - ComponentLabel: "componentname", + KubernetesInstanceLabel: "componentname", }, }, } diff --git a/pkg/component/pushed_component.go b/pkg/component/pushed_component.go index 73b6667397b..25dee1bb3af 100644 --- a/pkg/component/pushed_component.go +++ b/pkg/component/pushed_component.go @@ -11,7 +11,6 @@ import ( v1 "k8s.io/api/apps/v1" v12 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/klog" ) type provider interface { @@ -143,22 +142,24 @@ func (d devfileComponent) GetEnvVars() []v12.EnvVar { func (d devfileComponent) GetLabels() map[string]string { return d.d.Labels } - func (d devfileComponent) GetAnnotations() map[string]string { return d.d.Annotations } func (d devfileComponent) GetName() string { - return d.d.Labels[componentlabels.ComponentLabel] + return d.d.Labels[componentlabels.KubernetesInstanceLabel] } func getType(component provider) (string, error) { - if componentType, ok := component.GetAnnotations()[componentlabels.ComponentTypeAnnotation]; ok { + + // For backwards compatibility with previously deployed components that could be non-odo, check the annotation first + // then check to see if there is a label with the project type + if componentType, ok := component.GetAnnotations()[componentlabels.OdoProjectTypeAnnotation]; ok { + return componentType, nil + } else if componentType, ok = component.GetLabels()[componentlabels.OdoProjectTypeAnnotation]; ok { return componentType, nil - } else if _, ok = component.GetLabels()[componentlabels.ComponentTypeLabel]; ok { - klog.V(1).Info("No annotation assigned; retuning 'Not available' since labels are assigned. Annotations will be assigned when user pushes again.") - return NotAvailable, nil } + return "", fmt.Errorf("%s component doesn't provide a type annotation; consider pushing the component again", component.GetName()) } @@ -202,4 +203,5 @@ func isIgnorableError(err error) bool { return true } return kerrors.IsNotFound(err) || kerrors.IsForbidden(err) || kerrors.IsUnauthorized(err) + } diff --git a/pkg/component/types.go b/pkg/component/types.go index 9e1c1b9781c..fba48ddac09 100644 --- a/pkg/component/types.go +++ b/pkg/component/types.go @@ -49,7 +49,7 @@ type SecretMount struct { // ComponentStatus is Status of components type ComponentStatus struct { Context string `json:"context,omitempty"` - State State `json:"state"` + State string `json:"state"` LinkedServices []SecretMount `json:"linkedServices,omitempty"` } @@ -61,16 +61,13 @@ type CombinedComponentList struct { OtherComponents []Component `json:"otherComponents"` } -// State represents the component state -type State string - const ( // StateTypePushed means that Storage is present both locally and on cluster - StateTypePushed State = "Pushed" + StateTypePushed = "Pushed" // StateTypeNotPushed means that Storage is only in local config, but not on the cluster - StateTypeNotPushed State = "Not Pushed" + StateTypeNotPushed = "Not Pushed" // StateTypeUnknown means that odo cannot tell its state - StateTypeUnknown State = "Unknown" + StateTypeUnknown = "Unknown" ) func newComponentWithType(componentName, componentType string) Component { diff --git a/pkg/deploy/deploy.go b/pkg/deploy/deploy.go index 9fd676bbb7c..ab96dc09139 100644 --- a/pkg/deploy/deploy.go +++ b/pkg/deploy/deploy.go @@ -55,22 +55,26 @@ func (o *deployHandler) ApplyImage(img v1alpha2.Component) error { return image.BuildPushSpecificImage(o.devfileObj, o.path, img, true) } +// ApplyKubernetes applies inline Kubernetes YAML from the devfile.yaml file func (o *deployHandler) ApplyKubernetes(kubernetes v1alpha2.Component) error { - // validate if the GVRs represented by Kubernetes inlined components are supported by the underlying cluster + + // Validate if the GVRs represented by Kubernetes inlined components are supported by the underlying cluster _, err := service.ValidateResourceExist(o.kubeClient, kubernetes, o.path) if err != nil { return err } // Get the most common labels that's applicable to all resources being deployed. - // Retrieve the component type from the devfile and also inject it into the list of labels // Set the mode to DEPLOY. Regardless of what Kubernetes resource we are deploying. labels := componentlabels.GetLabels(o.devfileObj.Data.GetMetadata().Name, o.appName, true) - componentType := component.GetComponentTypeFromDevfileMetadata(o.devfileObj.Data.GetMetadata()) - labels[componentlabels.ComponentProjectTypeLabel] = componentType - labels[componentlabels.ComponentModeLabel] = componentlabels.ComponentDeployLabel + labels[componentlabels.OdoModeLabel] = componentlabels.ComponentDeployName klog.V(4).Infof("Injecting labels: %+v into k8s artifact", labels) + // Create the annotations + // Retrieve the component type from the devfile and also inject it into the list of annotations + annotations := make(map[string]string) + annotations[componentlabels.OdoProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(o.devfileObj.Data.GetMetadata()) + // Get the Kubernetes component u, err := service.GetK8sComponentAsUnstructured(kubernetes.Kubernetes, o.path, devfilefs.DefaultFs{}) if err != nil { @@ -79,7 +83,7 @@ func (o *deployHandler) ApplyKubernetes(kubernetes v1alpha2.Component) error { // Deploy the actual Kubernetes component and error out if there's an issue. log.Infof("\nDeploying Kubernetes %s: %s", u.GetKind(), u.GetName()) - isOperatorBackedService, err := service.PushKubernetesResource(o.kubeClient, u, labels) + isOperatorBackedService, err := service.PushKubernetesResource(o.kubeClient, u, labels, annotations) if err != nil { return errors.Wrap(err, "failed to create service(s) associated with the component") } diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index 823cb53638a..480e58be8ef 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -112,13 +112,18 @@ type Adapter struct { // Once the component has started, it will sync the source code to it. func (a Adapter) Push(parameters common.PushParameters) (err error) { - a.deployment, err = a.Client.GetOneDeployment(a.ComponentName, a.AppName) + // Get the Dev deployment: + // Since `odo deploy` can theoretically deploy a deployment as well with the same instance name + // we make sure that we are retrieving the deployment with the Dev mode, NOT Deploy. + selectorLabels := componentlabels.GetLabels(a.ComponentName, a.AppName, false) + selectorLabels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName + a.deployment, err = a.Client.GetOneDeploymentFromSelector(util.ConvertLabelsToSelector(selectorLabels)) + if err != nil { if _, ok := err.(*kclient.DeploymentNotFoundError); !ok { return errors.Wrapf(err, "unable to determine if component %s exists", a.ComponentName) } } - componentExists := a.deployment != nil a.devfileBuildCmd = parameters.DevfileBuildCmd @@ -162,7 +167,13 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { return fmt.Errorf("failed to validate devfile build and run commands: %w", err) } + // Set the mode to Dev since we are using "odo push" here labels := componentlabels.GetLabels(a.ComponentName, a.AppName, true) + labels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName + + // Set the annotations for the component type + annotations := make(map[string]string) + annotations[componentlabels.OdoProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata()) previousMode := parameters.EnvSpecificInfo.GetRunMode() currentMode := envinfo.Run @@ -170,7 +181,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { if parameters.Debug { pushDevfileDebugCommands, e := common.ValidateAndGetDebugDevfileCommands(a.Devfile.Data, a.devfileDebugCmd) if e != nil { - return fmt.Errorf("debug command is not valid") + return fmt.Errorf("debug command is not valid: %w", err) } pushDevfileCommands[devfilev1.DebugCommandGroupKind] = pushDevfileDebugCommands currentMode = envinfo.Debug @@ -194,7 +205,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { } // create the Kubernetes objects from the manifest and delete the ones not in the devfile - err = service.PushKubernetesResources(a.Client, k8sComponents, labels, a.Context) + err = service.PushKubernetesResources(a.Client, k8sComponents, labels, annotations, a.Context) if err != nil { return errors.Wrap(err, "failed to create service(s) associated with the component") } @@ -234,6 +245,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { } } + // Update all services with owner references err = service.UpdateServicesWithOwnerReferences(a.Client, k8sComponents, ownerReference, a.Context) if err != nil { return err @@ -254,7 +266,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { a.deployment, err = a.Client.WaitForDeploymentRollout(a.deployment.Name) if err != nil { - return errors.Wrap(err, "error while waiting for deployment rollout") + return errors.Wrapf(err, "Failed to update config to component deployed.") } // Wait for Pod to be in running state otherwise we can't sync data or exec commands to it. @@ -266,7 +278,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) { parameters.EnvSpecificInfo.SetDevfileObj(a.Devfile) err = component.ApplyConfig(a.Client, parameters.EnvSpecificInfo) if err != nil { - return errors.Wrapf(err, "Failed to update config to component deployed.") + return errors.Wrap(err, "failed to update config to component deployed.") } // Compare the name of the pod with the one before the rollout. If they differ, it means there's a new pod and a force push is required @@ -393,6 +405,7 @@ func (a Adapter) CheckSupervisordCommandStatus(command devfilev1.Command) error func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSpecificInfo, isMainStorageEphemeral bool) (err error) { ei.SetDevfileObj(a.Devfile) + componentName := a.ComponentName storageClient := storagepkg.NewClient(storagepkg.ClientOptions{ Client: a.Client, @@ -400,7 +413,7 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp }) // handle the ephemeral storage - err = storage.HandleEphemeralStorage(a.Client, storageClient, a.ComponentName, isMainStorageEphemeral) + err = storage.HandleEphemeralStorage(a.Client, storageClient, componentName, isMainStorageEphemeral) if err != nil { return err } @@ -411,19 +424,14 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp return err } - componentName := a.ComponentName - var componentType string - // We insert the component type in deployment annotations because its value might be in a namespaced/versioned format, - // since labels do not support such formats, we extract the component type from these formats before assigning its value to the corresponding label. - // This annotated value will later be used when listing the components; we do this to list/describe and stay inline with the component type value set in the devfile. - annotatedComponentType := component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata()) - if annotatedComponentType != component.NotAvailable { - componentType = strings.TrimSuffix(dfutil.ExtractComponentType(componentType), "-") - } - + // Set the labels labels := componentlabels.GetLabels(componentName, a.AppName, true) + labels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName labels["component"] = componentName - labels[componentlabels.ComponentTypeLabel] = componentType + + annotations := make(map[string]string) + annotations[componentlabels.OdoProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata()) + klog.V(4).Infof("We are deploying these annotations: %s", annotations) containers, err := generator.GetContainers(a.Devfile, parsercommon.DevfileOptions{}) if err != nil { @@ -449,7 +457,7 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp initContainers = append(initContainers, kclient.GetBootstrapSupervisordInitContainer()) // list all the pvcs for the component - pvcs, err := a.Client.ListPVCs(fmt.Sprintf("%v=%v", "component", a.ComponentName)) + pvcs, err := a.Client.ListPVCs(fmt.Sprintf("%v=%v", "component", componentName)) if err != nil { return err } @@ -481,7 +489,7 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp "component": componentName, } - deploymentObjectMeta, err := a.generateDeploymentObjectMeta(labels) + deploymentObjectMeta, err := a.generateDeploymentObjectMeta(labels, annotations) if err != nil { return err } @@ -504,9 +512,6 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp deployment.Annotations = make(map[string]string) } - // Add annotation for component type; this will later be used while listing/describing a component - deployment.Annotations[componentlabels.ComponentTypeAnnotation] = annotatedComponentType - if vcsUri := util.GetGitOriginPath(a.Context); vcsUri != "" { deployment.Annotations["app.openshift.io/vcs-uri"] = vcsUri } @@ -536,17 +541,19 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp // If the component already exists, get the resource version of the deploy before updating klog.V(2).Info("The component already exists, attempting to update it") if a.Client.IsSSASupported() { + klog.V(4).Info("Applying deployment") a.deployment, err = a.Client.ApplyDeployment(*deployment) } else { + klog.V(4).Info("Updating deployment") a.deployment, err = a.Client.UpdateDeployment(*deployment) } if err != nil { return err } klog.V(2).Infof("Successfully updated component %v", componentName) - e := a.createOrUpdateServiceForComponent(svc, componentName) - if e != nil { - return e + err = a.createOrUpdateServiceForComponent(svc, componentName) + if err != nil { + return err } } else { if a.Client.IsSSASupported() { @@ -558,6 +565,7 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp if err != nil { return err } + klog.V(2).Infof("Successfully created component %v", componentName) ownerReference := generator.GetOwnerReference(a.deployment) svc.OwnerReferences = append(svc.OwnerReferences, ownerReference) @@ -603,17 +611,17 @@ func (a *Adapter) createOrUpdateServiceForComponent(svc *corev1.Service, compone return a.Client.DeleteService(oldSvc.Name) } -// generateDeploymentObjectMeta generates a ObjectMeta object for the given deployment's name and labels +// generateDeploymentObjectMeta generates a ObjectMeta object for the given deployment's name, labels and annotations // if no deployment exists, it creates a new deployment name -func (a Adapter) generateDeploymentObjectMeta(labels map[string]string) (metav1.ObjectMeta, error) { +func (a Adapter) generateDeploymentObjectMeta(labels map[string]string, annotations map[string]string) (metav1.ObjectMeta, error) { if a.deployment != nil { - return generator.GetObjectMeta(a.deployment.Name, a.Client.GetCurrentNamespace(), labels, nil), nil + return generator.GetObjectMeta(a.deployment.Name, a.Client.GetCurrentNamespace(), labels, annotations), nil } else { deploymentName, err := util.NamespaceKubernetesObject(a.ComponentName, a.AppName) if err != nil { return metav1.ObjectMeta{}, err } - return generator.GetObjectMeta(deploymentName, a.Client.GetCurrentNamespace(), labels, nil), nil + return generator.GetObjectMeta(deploymentName, a.Client.GetCurrentNamespace(), labels, annotations), nil } } diff --git a/pkg/devfile/adapters/kubernetes/component/adapter_test.go b/pkg/devfile/adapters/kubernetes/component/adapter_test.go index b377071459d..ee97024c86c 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter_test.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter_test.go @@ -20,6 +20,7 @@ import ( "github.com/devfile/library/pkg/testingutil" applabels "github.com/redhat-developer/odo/pkg/application/labels" componentLabels "github.com/redhat-developer/odo/pkg/component/labels" + componentlabels "github.com/redhat-developer/odo/pkg/component/labels" adaptersCommon "github.com/redhat-developer/odo/pkg/devfile/adapters/common" "github.com/redhat-developer/odo/pkg/kclient" odoTestingUtil "github.com/redhat-developer/odo/pkg/testingutil" @@ -46,11 +47,11 @@ func TestCreateOrUpdateComponent(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: testComponentName, Labels: map[string]string{ - applabels.ApplicationLabel: testAppName, - componentLabels.ComponentLabel: testComponentName, + applabels.ApplicationLabel: testAppName, + componentLabels.KubernetesInstanceLabel: testComponentName, }, Annotations: map[string]string{ - componentLabels.ComponentTypeAnnotation: "", + componentLabels.OdoProjectTypeAnnotation: "", }, }, } @@ -95,7 +96,7 @@ func TestCreateOrUpdateComponent(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var comp devfilev1.Component if tt.componentType != "" { - deployment.Annotations[componentLabels.ComponentTypeAnnotation] = string(tt.componentType) + deployment.Annotations[componentLabels.OdoProjectTypeAnnotation] = string(tt.componentType) comp = testingutil.GetFakeContainerComponent("component") } devObj := devfileParser.DevfileObj{ @@ -632,7 +633,8 @@ func TestAdapter_generateDeploymentObjectMeta(t *testing.T) { deployment *v1.Deployment } type args struct { - labels map[string]string + labels map[string]string + annotations map[string]string } tests := []struct { name string @@ -649,7 +651,8 @@ func TestAdapter_generateDeploymentObjectMeta(t *testing.T) { deployment: odoTestingUtil.CreateFakeDeployment("nodejs"), }, args: args{ - labels: odoTestingUtil.CreateFakeDeployment("nodejs").Labels, + labels: odoTestingUtil.CreateFakeDeployment("nodejs").Labels, + annotations: nil, }, want: generator.GetObjectMeta("nodejs", "project-0", odoTestingUtil.CreateFakeDeployment("nodejs").Labels, nil), wantErr: false, @@ -662,11 +665,26 @@ func TestAdapter_generateDeploymentObjectMeta(t *testing.T) { deployment: nil, }, args: args{ - labels: odoTestingUtil.CreateFakeDeployment("nodejs").Labels, + labels: odoTestingUtil.CreateFakeDeployment("nodejs").Labels, + annotations: nil, }, want: generator.GetObjectMeta(namespacedKubernetesName, "project-0", odoTestingUtil.CreateFakeDeployment("nodejs").Labels, nil), wantErr: false, }, + { + name: "case 3: deployment exists and there is annotations successfully passed in", + fields: fields{ + componentName: "nodejs", + appName: "app", + deployment: odoTestingUtil.CreateFakeDeployment("nodejs"), + }, + args: args{ + labels: odoTestingUtil.CreateFakeDeployment("nodejs").Labels, + annotations: map[string]string{componentlabels.OdoModeLabel: componentlabels.ComponentDevName}, + }, + want: generator.GetObjectMeta("nodejs", "project-0", odoTestingUtil.CreateFakeDeployment("nodejs").Labels, map[string]string{componentlabels.OdoModeLabel: componentlabels.ComponentDevName}), + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -683,7 +701,7 @@ func TestAdapter_generateDeploymentObjectMeta(t *testing.T) { }, deployment: tt.fields.deployment, } - got, err := a.generateDeploymentObjectMeta(tt.args.labels) + got, err := a.generateDeploymentObjectMeta(tt.args.labels, tt.args.annotations) if (err != nil) != tt.wantErr { t.Errorf("generateDeploymentObjectMeta() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/pkg/devfile/adapters/kubernetes/storage/utils.go b/pkg/devfile/adapters/kubernetes/storage/utils.go index 8c628945a80..5ba1fb60139 100644 --- a/pkg/devfile/adapters/kubernetes/storage/utils.go +++ b/pkg/devfile/adapters/kubernetes/storage/utils.go @@ -189,7 +189,7 @@ func generateVolumeNameFromPVC(pvc string) (volumeName string, err error) { // HandleEphemeralStorage creates or deletes the ephemeral volume based on the preference setting func HandleEphemeralStorage(client kclient.ClientInterface, storageClient storage.Client, componentName string, isEphemeral bool) error { - selector := fmt.Sprintf("%v=%s,%s=%s", componentlabels.ComponentLabel, componentName, storagelabels.SourcePVCLabel, storage.OdoSourceVolume) + selector := fmt.Sprintf("%v=%s,%s=%s", componentlabels.KubernetesInstanceLabel, componentName, storagelabels.SourcePVCLabel, storage.OdoSourceVolume) pvcs, err := client.ListPVCs(selector) if err != nil && !kerrors.IsNotFound(err) { diff --git a/pkg/kclient/deployments.go b/pkg/kclient/deployments.go index 614865bf66c..46348a900c6 100644 --- a/pkg/kclient/deployments.go +++ b/pkg/kclient/deployments.go @@ -325,7 +325,6 @@ func (c *Client) DeleteDeployment(labels map[string]string) error { func (c *Client) CreateDynamicResource(resource unstructured.Unstructured, gvr *meta.RESTMapping) error { klog.V(5).Infoln("Applying resource via server-side apply:") klog.V(5).Infoln(resourceAsJson(resource.Object)) - data, err := json.Marshal(resource.Object) if err != nil { return errors.Wrapf(err, "unable to marshal resource") diff --git a/pkg/kclient/fake/ingress.go b/pkg/kclient/fake/ingress.go index f71cfe6f887..472f2a3e434 100644 --- a/pkg/kclient/fake/ingress.go +++ b/pkg/kclient/fake/ingress.go @@ -20,12 +20,12 @@ func GetKubernetesIngressListWithMultiple(componentName, appName string, network ObjectMeta: metav1.ObjectMeta{ Name: "example-0", Labels: map[string]string{ - applabels.ApplicationLabel: appName, - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: "example-0", - applabels.App: appName, + applabels.ApplicationLabel: appName, + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: "example-0", + applabels.App: appName, }, }, IngressSpecParams: generator.IngressSpecParams{ @@ -45,12 +45,12 @@ func GetKubernetesIngressListWithMultiple(componentName, appName string, network ObjectMeta: metav1.ObjectMeta{ Name: "example-1", Labels: map[string]string{ - applabels.ApplicationLabel: "app", - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: "example-1", - applabels.App: "app", + applabels.ApplicationLabel: "app", + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: "example-1", + applabels.App: "app", }, }, IngressSpecParams: generator.IngressSpecParams{ @@ -74,12 +74,12 @@ func GetSingleKubernetesIngress(urlName, componentName, appName string, networki ObjectMeta: metav1.ObjectMeta{ Name: urlName, Labels: map[string]string{ - applabels.ApplicationLabel: appName, - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: urlName, - applabels.App: appName, + applabels.ApplicationLabel: appName, + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: urlName, + applabels.App: appName, }, }, IngressSpecParams: generator.IngressSpecParams{ @@ -109,12 +109,12 @@ func GetSingleSecureKubernetesIngress(urlName, componentName, appName, secretNam ObjectMeta: metav1.ObjectMeta{ Name: urlName, Labels: map[string]string{ - applabels.ApplicationLabel: appName, - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: urlName, - applabels.App: appName, + applabels.ApplicationLabel: appName, + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: urlName, + applabels.App: appName, }, }, IngressSpecParams: generator.IngressSpecParams{ diff --git a/pkg/service/link.go b/pkg/service/link.go index 2ea8c2c57dd..2d7b8d77cdd 100644 --- a/pkg/service/link.go +++ b/pkg/service/link.go @@ -134,7 +134,7 @@ func pushLinksWithoutOperator(client kclient.ClientInterface, k8sComponents []de return false, err } - secrets, err := client.ListSecrets(componentlabels.GetSelector(labels[componentlabels.ComponentLabel], labels[applabels.ApplicationLabel])) + secrets, err := client.ListSecrets(componentlabels.GetSelector(labels[componentlabels.KubernetesInstanceLabel], labels[applabels.ApplicationLabel])) if err != nil { return false, err } @@ -244,7 +244,7 @@ func pushLinksWithoutOperator(client kclient.ClientInterface, k8sComponents []de // get the services and get match them against the component serviceCompMap = make(map[string]string) for _, service := range services { - serviceCompMap[service.Name] = service.Labels[componentlabels.ComponentLabel] + serviceCompMap[service.Name] = service.Labels[componentlabels.KubernetesInstanceLabel] } } diff --git a/pkg/service/service.go b/pkg/service/service.go index fb762f1c3a4..97842d1b339 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -198,7 +198,7 @@ func listDevfileLinks(devfileObj parser.DevfileObj, context string, fs devfilefs } // PushKubernetesResources updates service(s) from Kubernetes Inlined component in a devfile by creating new ones or removing old ones -func PushKubernetesResources(client kclient.ClientInterface, k8sComponents []devfile.Component, labels map[string]string, context string) error { +func PushKubernetesResources(client kclient.ClientInterface, k8sComponents []devfile.Component, labels map[string]string, annotations map[string]string, context string) error { // check csv support before proceeding csvSupported, err := client.IsCSVSupported() if err != nil { @@ -226,7 +226,7 @@ func PushKubernetesResources(client kclient.ClientInterface, k8sComponents []dev if er != nil { return er } - _, er = PushKubernetesResource(client, u, labels) + _, er = PushKubernetesResource(client, u, labels, annotations) if er != nil { return er } @@ -253,7 +253,7 @@ func PushKubernetesResources(client kclient.ClientInterface, k8sComponents []dev // PushKubernetesResource pushes a Kubernetes resource (u) to the cluster using client // adding labels to the resource -func PushKubernetesResource(client kclient.ClientInterface, u unstructured.Unstructured, labels map[string]string) (bool, error) { +func PushKubernetesResource(client kclient.ClientInterface, u unstructured.Unstructured, labels map[string]string, annotations map[string]string) (bool, error) { if isLinkResource(u.GetKind()) { // it's a service binding related resource return false, nil @@ -264,9 +264,11 @@ func PushKubernetesResource(client kclient.ClientInterface, u unstructured.Unstr return false, err } - // Add all passed in labels to the deployment regardless if it's an operator or not - existingLabels := u.GetLabels() - u.SetLabels(mergeLabels(existingLabels, labels)) + // Add all passed in labels to the k8s resource regardless if it's an operator or not + u.SetLabels(mergeMaps(u.GetLabels(), labels)) + + // Pass in all annotations to the k8s resource + u.SetAnnotations(mergeMaps(u.GetAnnotations(), annotations)) err = createOperatorService(client, u) return isOp, err @@ -312,16 +314,16 @@ func GetK8sComponentAsUnstructured(component *devfile.KubernetesComponent, conte return u, nil } -func mergeLabels(labels ...map[string]string) map[string]string { - mergedLabels := map[string]string{} +func mergeMaps(maps ...map[string]string) map[string]string { + mergedMaps := map[string]string{} - for _, l := range labels { + for _, l := range maps { for k, v := range l { - mergedLabels[k] = v + mergedMaps[k] = v } } - return mergedLabels + return mergedMaps } // DeployedInfo holds information about the services present on the cluster @@ -343,7 +345,7 @@ func ListDeployedServices(client kclient.ClientInterface, labels map[string]stri name := svc.GetName() kind := svc.GetKind() deployedLabels := svc.GetLabels() - if deployedLabels[applabels.ManagedBy] == "odo" && deployedLabels[componentlabels.ComponentLabel] == labels[componentlabels.ComponentLabel] { + if deployedLabels[applabels.ManagedBy] == "odo" && deployedLabels[componentlabels.KubernetesInstanceLabel] == labels[componentlabels.KubernetesInstanceLabel] { deployed[kind+"/"+name] = DeployedInfo{ Kind: kind, Name: name, diff --git a/pkg/storage/labels/labels_test.go b/pkg/storage/labels/labels_test.go index b3c1c344b6e..ad29eaebd91 100644 --- a/pkg/storage/labels/labels_test.go +++ b/pkg/storage/labels/labels_test.go @@ -30,9 +30,9 @@ func TestGetLabels(t *testing.T) { additional: false, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - componentlabels.ComponentLabel: "componentname", - StorageLabel: "storagename", + applabels.ApplicationLabel: "applicationame", + componentlabels.KubernetesInstanceLabel: "componentname", + StorageLabel: "storagename", }, }, { name: "Case 2: No storage name", @@ -43,9 +43,9 @@ func TestGetLabels(t *testing.T) { additional: false, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - componentlabels.ComponentLabel: "componentname", - StorageLabel: "", + applabels.ApplicationLabel: "applicationame", + componentlabels.KubernetesInstanceLabel: "componentname", + StorageLabel: "", }, }, { name: "Case 3: Everything with additional", @@ -56,12 +56,12 @@ func TestGetLabels(t *testing.T) { additional: true, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - applabels.App: "applicationame", - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - componentlabels.ComponentLabel: "componentname", - StorageLabel: "storagename", + applabels.ApplicationLabel: "applicationame", + applabels.App: "applicationame", + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + componentlabels.KubernetesInstanceLabel: "componentname", + StorageLabel: "storagename", }, }, } diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 739fb12f0dd..6b2b0196e7e 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -55,7 +55,7 @@ func NewClient(options ClientOptions) Client { if options.Deployment != nil { genericInfo.appName = options.Deployment.Labels[applabels.ApplicationLabel] - genericInfo.componentName = options.Deployment.Labels[labels.ComponentLabel] + genericInfo.componentName = options.Deployment.Labels[labels.KubernetesInstanceLabel] } return kubernetesClient{ diff --git a/pkg/testingutil/deployments.go b/pkg/testingutil/deployments.go index e044ae46185..98aa3de35dd 100644 --- a/pkg/testingutil/deployments.go +++ b/pkg/testingutil/deployments.go @@ -14,17 +14,21 @@ func CreateFakeDeployment(podName string) *appsv1.Deployment { fakeUID := types.UID("12345") deployment := appsv1.Deployment{ + TypeMeta: metav1.TypeMeta{ + Kind: "Component", + APIVersion: "odo.dev/v1alpha1", + }, ObjectMeta: metav1.ObjectMeta{ Name: podName, UID: fakeUID, Labels: map[string]string{ - applabels.App: "app", - applabels.ApplicationLabel: "app", - componentlabels.ComponentLabel: podName, - applabels.ManagedBy: "odo", + applabels.App: "app", + applabels.ApplicationLabel: "app", + componentlabels.KubernetesInstanceLabel: podName, + applabels.ManagedBy: "odo", }, Annotations: map[string]string{ - componentlabels.ComponentTypeAnnotation: podName, + componentlabels.OdoProjectTypeAnnotation: podName, }, }, } diff --git a/pkg/testingutil/routes.go b/pkg/testingutil/routes.go index c48141268db..e14ee125493 100644 --- a/pkg/testingutil/routes.go +++ b/pkg/testingutil/routes.go @@ -28,11 +28,11 @@ func GetSingleRoute(urlName string, port int, componentName, applicationName str ObjectMeta: metav1.ObjectMeta{ Name: urlName, Labels: map[string]string{ - applabels.ApplicationLabel: applicationName, - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: urlName, + applabels.ApplicationLabel: applicationName, + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: urlName, }, }, Spec: routev1.RouteSpec{ @@ -55,12 +55,12 @@ func GetSingleSecureRoute(urlName string, port int, componentName, applicationNa ObjectMeta: metav1.ObjectMeta{ Name: urlName, Labels: map[string]string{ - applabels.ApplicationLabel: applicationName, - componentlabels.ComponentLabel: componentName, - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - labels.URLLabel: urlName, - applabels.App: applicationName, + applabels.ApplicationLabel: applicationName, + componentlabels.KubernetesInstanceLabel: componentName, + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + labels.URLLabel: urlName, + applabels.App: applicationName, }, }, RouteSpecParams: generator.RouteSpecParams{ diff --git a/pkg/url/labels/labels_test.go b/pkg/url/labels/labels_test.go index da94b84bdee..ee4256672dc 100644 --- a/pkg/url/labels/labels_test.go +++ b/pkg/url/labels/labels_test.go @@ -30,9 +30,9 @@ func TestGetLabels(t *testing.T) { additional: false, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - componentlabels.ComponentLabel: "componentname", - URLLabel: "urlname", + applabels.ApplicationLabel: "applicationame", + componentlabels.KubernetesInstanceLabel: "componentname", + URLLabel: "urlname", }, }, { name: "Case 2: No URL name", @@ -43,9 +43,9 @@ func TestGetLabels(t *testing.T) { additional: false, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - componentlabels.ComponentLabel: "componentname", - URLLabel: "", + applabels.ApplicationLabel: "applicationame", + componentlabels.KubernetesInstanceLabel: "componentname", + URLLabel: "", }, }, { name: "Case 3: Everything with additional", @@ -56,12 +56,12 @@ func TestGetLabels(t *testing.T) { additional: true, }, want: map[string]string{ - applabels.ApplicationLabel: "applicationame", - applabels.App: "applicationame", - applabels.ManagedBy: "odo", - applabels.ManagerVersion: version.VERSION, - componentlabels.ComponentLabel: "componentname", - URLLabel: "urlname", + applabels.ApplicationLabel: "applicationame", + applabels.App: "applicationame", + applabels.ManagedBy: "odo", + applabels.ManagerVersion: version.VERSION, + componentlabels.KubernetesInstanceLabel: "componentname", + URLLabel: "urlname", }, }, } diff --git a/pkg/url/url.go b/pkg/url/url.go index 1150b26ae8a..199de66a79c 100644 --- a/pkg/url/url.go +++ b/pkg/url/url.go @@ -49,7 +49,7 @@ func NewClient(options ClientOptions) Client { if options.Deployment != nil { genericInfo.appName = options.Deployment.Labels[applabels.ApplicationLabel] - genericInfo.componentName = options.Deployment.Labels[labels.ComponentLabel] + genericInfo.componentName = options.Deployment.Labels[labels.KubernetesInstanceLabel] } return kubernetesClient{ diff --git a/tests/helper/helper_kubectl.go b/tests/helper/helper_kubectl.go index b61344fd637..bdbdb7b27df 100644 --- a/tests/helper/helper_kubectl.go +++ b/tests/helper/helper_kubectl.go @@ -189,7 +189,7 @@ func (kubectl KubectlRunner) DeleteNamespaceProject(projectName string) { func (kubectl KubectlRunner) GetEnvsDevFileDeployment(componentName, appName, projectName string) map[string]string { var mapOutput = make(map[string]string) - selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.ComponentLabel, componentName, applabels.ApplicationLabel, appName) + selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.KubernetesInstanceLabel, componentName, applabels.ApplicationLabel, appName) output := Cmd(kubectl.path, "get", "deployment", selector, "--namespace", projectName, "-o", "jsonpath='{range .items[0].spec.template.spec.containers[0].env[*]}{.name}:{.value}{\"\\n\"}{end}'").ShouldPass().Out() diff --git a/tests/helper/helper_oc.go b/tests/helper/helper_oc.go index 73f5c759489..ecb0cf54f3b 100644 --- a/tests/helper/helper_oc.go +++ b/tests/helper/helper_oc.go @@ -263,7 +263,7 @@ func (oc OcRunner) GetEnvFromEntry(componentName string, appName string, project func (oc OcRunner) GetEnvsDevFileDeployment(componentName, appName, projectName string) map[string]string { var mapOutput = make(map[string]string) - selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.ComponentLabel, componentName, applabels.ApplicationLabel, appName) + selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.KubernetesInstanceLabel, componentName, applabels.ApplicationLabel, appName) output := Cmd(oc.path, "get", "deployment", selector, "--namespace", projectName, "-o", "jsonpath='{range .items[0].spec.template.spec.containers[0].env[*]}{.name}:{.value}{\"\\n\"}{end}'").ShouldPass().Out() diff --git a/tests/helper/helper_run.go b/tests/helper/helper_run.go index 26e88f3c6f6..1d0a9677bcb 100644 --- a/tests/helper/helper_run.go +++ b/tests/helper/helper_run.go @@ -74,7 +74,7 @@ func WaitAndCheckForTerminatingState(path, resourceType, namespace string, timeo func GetAnnotationsDeployment(path, componentName, appName, projectName string) map[string]string { var mapOutput = make(map[string]string) - selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.ComponentLabel, componentName, applabels.ApplicationLabel, appName) + selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.KubernetesInstanceLabel, componentName, applabels.ApplicationLabel, appName) output := Cmd(path, "get", "deployment", selector, "--namespace", projectName, "-o", "go-template='{{ range $k, $v := (index .items 0).metadata.annotations}}{{$k}}:{{$v}}{{\"\\n\"}}{{end}}'").ShouldPass().Out() @@ -101,7 +101,7 @@ func GetSecrets(path, project string) string { // GetEnvRefNames gets the ref values from the envFroms of the deployment belonging to the given data func GetEnvRefNames(path, componentName, appName, projectName string) []string { - selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.ComponentLabel, componentName, applabels.ApplicationLabel, appName) + selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.KubernetesInstanceLabel, componentName, applabels.ApplicationLabel, appName) output := Cmd(path, "get", "deployment", selector, "--namespace", projectName, "-o", "jsonpath='{range .items[0].spec.template.spec.containers[0].envFrom[*]}{.secretRef.name}{\"\\n\"}{end}'").ShouldPass().Out() @@ -123,7 +123,7 @@ func GetEnvFromEntry(path string, componentName string, appName string, projectN // GetVolumeNamesFromDeployment gets the volumes from the deployment belonging to the given data func GetVolumeNamesFromDeployment(path, componentName, appName, projectName string) map[string]string { var mapOutput = make(map[string]string) - selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.ComponentLabel, componentName, applabels.ApplicationLabel, appName) + selector := fmt.Sprintf("--selector=%s=%s,%s=%s", labels.KubernetesInstanceLabel, componentName, applabels.ApplicationLabel, appName) output := Cmd(path, "get", "deployment", selector, "--namespace", projectName, "-o", "jsonpath='{range .items[0].spec.template.spec.volumes[*]}{.name}{\":\"}{.persistentVolumeClaim.claimName}{\"\\n\"}{end}'").ShouldPass().Out()