Skip to content

Commit

Permalink
Review update / renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Drage <charlie@charliedrage.com>
  • Loading branch information
cdrage committed Mar 15, 2022
1 parent b6aa986 commit e48a539
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 122 deletions.
4 changes: 2 additions & 2 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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.ComponentKubernetesInstanceLabel], 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")
}
Expand Down Expand Up @@ -479,7 +479,7 @@ func setLinksServiceNames(client kclient.ClientInterface, linkedSecrets []Secret

serviceCompMap := make(map[string]string)
for _, gotService := range services {
serviceCompMap[gotService.Labels[componentlabels.ComponentKubernetesInstanceLabel]] = gotService.Name
serviceCompMap[gotService.Labels[componentlabels.KubernetesInstanceLabel]] = gotService.Name
}

for _, secret := range secrets {
Expand Down
20 changes: 10 additions & 10 deletions pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func TestList(t *testing.T) {
*testingutil.CreateFakeDeployment("comp1"),
}}

deploymentList.Items[0].Labels[componentlabels.ComponentKubernetesNameLabel] = "nodejs"
deploymentList.Items[0].Labels[componentlabels.KubernetesNameLabel] = "nodejs"
deploymentList.Items[0].Annotations = map[string]string{
componentlabels.ComponentProjectTypeAnnotation: "nodejs",
componentlabels.OdoProjectTypeAnnotation: "nodejs",
}
deploymentList.Items[1].Labels[componentlabels.ComponentKubernetesNameLabel] = "wildfly"
deploymentList.Items[1].Labels[componentlabels.KubernetesNameLabel] = "wildfly"
deploymentList.Items[1].Annotations = map[string]string{
componentlabels.ComponentProjectTypeAnnotation: "wildfly",
componentlabels.OdoProjectTypeAnnotation: "wildfly",
}
tests := []struct {
name string
Expand Down Expand Up @@ -484,14 +484,14 @@ func getFakeComponent(compName, namespace, appName, compType string, state strin
Name: compName,
Namespace: namespace,
Labels: map[string]string{
applabels.App: appName,
applabels.ManagedBy: "odo",
applabels.ApplicationLabel: appName,
componentlabels.ComponentKubernetesInstanceLabel: compName,
componentlabels.ComponentKubernetesNameLabel: compType,
applabels.App: appName,
applabels.ManagedBy: "odo",
applabels.ApplicationLabel: appName,
componentlabels.KubernetesInstanceLabel: compName,
componentlabels.KubernetesNameLabel: compType,
},
Annotations: map[string]string{
componentlabels.ComponentProjectTypeAnnotation: compType,
componentlabels.OdoProjectTypeAnnotation: compType,
},
},
Spec: ComponentSpec{
Expand Down
24 changes: 12 additions & 12 deletions pkg/component/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ import (
"github.com/redhat-developer/odo/pkg/util"
)

// ComponentKubernetesInstanceLabel is a label key used to identify the component name
const ComponentKubernetesInstanceLabel = "app.kubernetes.io/instance"
// KubernetesInstanceLabel is a label key used to identify the component name
const KubernetesInstanceLabel = "app.kubernetes.io/instance"

// ComponentKubernetesNameLabel is Kubernetes label that identifies the type of a component being used
const ComponentKubernetesNameLabel = "app.kubernetes.io/name"

// ComponentUnknownLabel is the label that is used to display something we do not know
const ComponentUnknownLabel = "<unknown>"
// KubernetesNameLabel is Kubernetes label that identifies the type of a component being used
const KubernetesNameLabel = "app.kubernetes.io/name"

// KubernetesManagedByLabel ...
const KubernetesManagedByLabel = "app.kubernetes.io/managed-by"

// ComponentModeLabel ...
const ComponentModeLabel = "odo.dev/mode"
// ComponentUnknownLabel is the label that is used to display something we do not know
const ComponentUnknownLabel = "<unknown>"

// ComponentDevName ...
const ComponentDevName = "Dev"
Expand All @@ -32,16 +29,19 @@ const ComponentNoneName = "None"
// ComponentPushedName ...
const ComponentPushedName = "Pushed"

// ComponentProjectTypeAnnotation ...
const ComponentProjectTypeAnnotation = "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
// if you are creating something use additional=true
// 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[ComponentKubernetesInstanceLabel] = componentName
labels[KubernetesInstanceLabel] = componentName
return labels
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/component/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestGetLabels(t *testing.T) {
additional: false,
},
want: map[string]string{
applabels.ApplicationLabel: "applicationame",
ComponentKubernetesInstanceLabel: "componentname",
applabels.ApplicationLabel: "applicationame",
KubernetesInstanceLabel: "componentname",
},
}, {
name: "everything with additional",
Expand All @@ -38,11 +38,11 @@ func TestGetLabels(t *testing.T) {
additional: true,
},
want: map[string]string{
applabels.ApplicationLabel: "applicationame",
applabels.App: "applicationame",
applabels.ManagedBy: "odo",
applabels.ManagerVersion: version.VERSION,
ComponentKubernetesInstanceLabel: "componentname",
applabels.ApplicationLabel: "applicationame",
applabels.App: "applicationame",
applabels.ManagedBy: "odo",
applabels.ManagerVersion: version.VERSION,
KubernetesInstanceLabel: "componentname",
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/component/pushed_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ func (d devfileComponent) GetAnnotations() map[string]string {
}

func (d devfileComponent) GetName() string {
return d.d.Labels[componentlabels.ComponentKubernetesInstanceLabel]
return d.d.Labels[componentlabels.KubernetesInstanceLabel]
}

func getType(component provider) (string, error) {

// For backwards compatibility with previously deployed components that could be non-odo, check the label first
// then check to see if there is an annotation with the project type
if componentType, ok := component.GetLabels()[componentlabels.ComponentProjectTypeAnnotation]; ok {
if componentType, ok := component.GetLabels()[componentlabels.OdoProjectTypeAnnotation]; ok {
return componentType, nil
} else if componentType, ok = component.GetAnnotations()[componentlabels.ComponentProjectTypeAnnotation]; ok {
} else if componentType, ok = component.GetAnnotations()[componentlabels.OdoProjectTypeAnnotation]; ok {
return componentType, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (o *deployHandler) ApplyKubernetes(kubernetes v1alpha2.Component) error {
// Get the most common labels that's applicable to all resources being deployed.
// Set the mode to DEPLOY. Regardless of what Kubernetes resource we are deploying.
labels := componentlabels.GetLabels(o.devfileObj.Data.GetMetadata().Name, o.appName, true)
labels[componentlabels.ComponentModeLabel] = componentlabels.ComponentDeployName
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.ComponentProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(o.devfileObj.Data.GetMetadata())
annotations[componentlabels.OdoProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(o.devfileObj.Data.GetMetadata())

// Get the Kubernetes component
u, err := service.GetK8sComponentAsUnstructured(kubernetes.Kubernetes, o.path, devfilefs.DefaultFs{})
Expand Down
14 changes: 7 additions & 7 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {
// 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.ComponentModeLabel] = componentlabels.ComponentDevName
selectorLabels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName
a.deployment, err = a.Client.GetOneDeploymentFromSelector(util.ConvertLabelsToSelector(selectorLabels))

if err != nil {
Expand Down Expand Up @@ -169,11 +169,11 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {

// Set the mode to Dev since we are using "odo push" here
labels := componentlabels.GetLabels(a.ComponentName, a.AppName, true)
labels[componentlabels.ComponentModeLabel] = componentlabels.ComponentDevName
labels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName

// Set the annotations for the component type
annotations := make(map[string]string)
annotations[componentlabels.ComponentProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata())
annotations[componentlabels.OdoProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata())

previousMode := parameters.EnvSpecificInfo.GetRunMode()
currentMode := envinfo.Run
Expand Down Expand Up @@ -426,11 +426,11 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp

// Set the labels
labels := componentlabels.GetLabels(componentName, a.AppName, true)
labels[componentlabels.ComponentModeLabel] = componentlabels.ComponentDevName
labels[componentlabels.OdoModeLabel] = componentlabels.ComponentDevName
labels["component"] = componentName

annotations := make(map[string]string)
annotations[componentlabels.ComponentProjectTypeAnnotation] = component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata())
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{})
Expand Down Expand Up @@ -551,9 +551,9 @@ func (a *Adapter) createOrUpdateComponent(componentExists bool, ei envinfo.EnvSp
return err
}
klog.V(2).Infof("Successfully updated component %v", componentName)
e := a.createOrUpdateServiceForComponent(svc, componentName)
err := a.createOrUpdateServiceForComponent(svc, componentName)
if err != nil {
return e
return err
}
} else {
if a.Client.IsSSASupported() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/devfile/adapters/kubernetes/component/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func TestCreateOrUpdateComponent(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: testComponentName,
Labels: map[string]string{
applabels.ApplicationLabel: testAppName,
componentLabels.ComponentKubernetesInstanceLabel: testComponentName,
applabels.ApplicationLabel: testAppName,
componentLabels.KubernetesInstanceLabel: testComponentName,
},
Annotations: map[string]string{
componentLabels.ComponentProjectTypeAnnotation: "",
componentLabels.OdoProjectTypeAnnotation: "",
},
},
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCreateOrUpdateComponent(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var comp devfilev1.Component
if tt.componentType != "" {
deployment.Annotations[componentLabels.ComponentProjectTypeAnnotation] = string(tt.componentType)
deployment.Annotations[componentLabels.OdoProjectTypeAnnotation] = string(tt.componentType)
comp = testingutil.GetFakeContainerComponent("component")
}
devObj := devfileParser.DevfileObj{
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.ComponentKubernetesInstanceLabel, 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) {
Expand Down
48 changes: 24 additions & 24 deletions pkg/kclient/fake/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func GetKubernetesIngressListWithMultiple(componentName, appName string, network
ObjectMeta: metav1.ObjectMeta{
Name: "example-0",
Labels: map[string]string{
applabels.ApplicationLabel: appName,
componentlabels.ComponentKubernetesInstanceLabel: 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{
Expand All @@ -45,12 +45,12 @@ func GetKubernetesIngressListWithMultiple(componentName, appName string, network
ObjectMeta: metav1.ObjectMeta{
Name: "example-1",
Labels: map[string]string{
applabels.ApplicationLabel: "app",
componentlabels.ComponentKubernetesInstanceLabel: 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{
Expand All @@ -74,12 +74,12 @@ func GetSingleKubernetesIngress(urlName, componentName, appName string, networki
ObjectMeta: metav1.ObjectMeta{
Name: urlName,
Labels: map[string]string{
applabels.ApplicationLabel: appName,
componentlabels.ComponentKubernetesInstanceLabel: 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{
Expand Down Expand Up @@ -109,12 +109,12 @@ func GetSingleSecureKubernetesIngress(urlName, componentName, appName, secretNam
ObjectMeta: metav1.ObjectMeta{
Name: urlName,
Labels: map[string]string{
applabels.ApplicationLabel: appName,
componentlabels.ComponentKubernetesInstanceLabel: 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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func pushLinksWithoutOperator(client kclient.ClientInterface, k8sComponents []de
return false, err
}

secrets, err := client.ListSecrets(componentlabels.GetSelector(labels[componentlabels.ComponentKubernetesInstanceLabel], labels[applabels.ApplicationLabel]))
secrets, err := client.ListSecrets(componentlabels.GetSelector(labels[componentlabels.KubernetesInstanceLabel], labels[applabels.ApplicationLabel]))
if err != nil {
return false, err
}
Expand Down Expand Up @@ -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.ComponentKubernetesInstanceLabel]
serviceCompMap[service.Name] = service.Labels[componentlabels.KubernetesInstanceLabel]
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,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.ComponentKubernetesInstanceLabel] == labels[componentlabels.ComponentKubernetesInstanceLabel] {
if deployedLabels[applabels.ManagedBy] == "odo" && deployedLabels[componentlabels.KubernetesInstanceLabel] == labels[componentlabels.KubernetesInstanceLabel] {
deployed[kind+"/"+name] = DeployedInfo{
Kind: kind,
Name: name,
Expand Down
Loading

0 comments on commit e48a539

Please sign in to comment.