Skip to content

Commit

Permalink
Move to pkg/labels + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Apr 5, 2022
1 parent a8e4ee4 commit 4368eee
Show file tree
Hide file tree
Showing 30 changed files with 88 additions and 81 deletions.
2 changes: 1 addition & 1 deletion pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/devfile/library/pkg/devfile/parser"
dfutil "github.com/devfile/library/pkg/util"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"

corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
devfilepkg "github.com/devfile/api/v2/pkg/devfile"
"github.com/golang/mock/gomock"
"github.com/kylelemons/godebug/pretty"
"github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/labels"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"k8s.io/klog"

"github.com/redhat-developer/odo/pkg/component"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
odoTestingUtil "github.com/redhat-developer/odo/pkg/testingutil"
"github.com/redhat-developer/odo/pkg/util"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/pushed_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"errors"
"fmt"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/storage"
v1 "k8s.io/api/apps/v1"
v12 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"k8s.io/klog"

"github.com/redhat-developer/odo/pkg/component"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/devfile/image"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/service"
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

"github.com/devfile/library/pkg/devfile/generator"
"github.com/redhat-developer/odo/pkg/component"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/devfile"
"github.com/redhat-developer/odo/pkg/devfile/adapters/common"
"github.com/redhat-developer/odo/pkg/devfile/adapters/kubernetes/storage"
"github.com/redhat-developer/odo/pkg/devfile/adapters/kubernetes/utils"
"github.com/redhat-developer/odo/pkg/envinfo"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/libdevfile"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/preference"
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
devfileParser "github.com/devfile/library/pkg/devfile/parser"
"github.com/devfile/library/pkg/testingutil"
odolabels "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"
odolabels "github.com/redhat-developer/odo/pkg/labels"
odoTestingUtil "github.com/redhat-developer/odo/pkg/testingutil"

v1 "k8s.io/api/apps/v1"
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 @@ -9,8 +9,8 @@ import (
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
dfutil "github.com/devfile/library/pkg/util"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/storage"
storagepkg "github.com/redhat-developer/odo/pkg/storage"

Expand Down
2 changes: 1 addition & 1 deletion pkg/kclient/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
apiMachineryWatch "k8s.io/apimachinery/pkg/watch"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/kclient/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kclient/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
devfileParser "github.com/devfile/library/pkg/devfile/parser"
parsercommon "github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/devfile/library/pkg/testingutil"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
odoTestingUtil "github.com/redhat-developer/odo/pkg/testingutil"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
4 changes: 2 additions & 2 deletions pkg/component/labels/builder.go → pkg/labels/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (o builder) WithAppName(name string) builder {
}

func (o builder) WithApp(name string) builder {
o.m[app] = name
o.m[appLabel] = name
return o
}

Expand Down Expand Up @@ -74,6 +74,6 @@ func (o builder) WithStorageName(name string) builder {
}

func (o builder) WithComponent(name string) builder {
o.m["component"] = name
o.m[componentLabel] = name
return o
}
53 changes: 53 additions & 0 deletions pkg/labels/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package labels

const (

// kubernetesInstanceLabel identifies the component name
kubernetesInstanceLabel = "app.kubernetes.io/instance"

// kubernetesNameLabel identifies the type of the component
// const kubernetesNameLabel = "app.kubernetes.io/name"

// kubernetesManagedByLabel identifies the manager of the component
kubernetesManagedByLabel = "app.kubernetes.io/managed-by"

// kubernetesManagedByVersionLabel identifies the version of manager used to deploy the resource
kubernetesManagedByVersionLabel = "app.kubernetes.io/managed-by-version"

// kubernetesPartOfLabel identifies the application to which the component belongs
kubernetesPartOfLabel = "app.kubernetes.io/part-of"

// kubernetesStorageNameLabel is applied to all storage resources that are created
kubernetesStorageNameLabel = "app.kubernetes.io/storage-name"

// odoModeLabel indicates which command were used to create the component, either dev or deploy
odoModeLabel = "odo.dev/mode"

// odoProjectTypeAnnotation indicates the project type fohe component
odoProjectTypeAnnotation = "odo.dev/project-type"

appLabel = "app"

componentLabel = "component"

// devfileStorageLabel is applied to all storage resources for devfile components that are created
devfileStorageLabel = "storage-name"

sourcePVCLabel = "odo-source-pvc"
)

const (
// ComponentDevMode indicates the resource is deployed using dev command
ComponentDevMode = "Dev"

// ComponentDeployMode indicates the resource is deployed using deploy command
ComponentDeployMode = "Deploy"

// ComponentAnyMode is used to search resources deployed using either dev or deploy comamnd
ComponentAnyMode = ""

ComponentNoneName = "None"

// odoManager is the value of the manager when a component is managed by odo
odoManager = "odo"
)
56 changes: 5 additions & 51 deletions pkg/component/labels/labels.go → pkg/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,17 @@ import (
"k8s.io/apimachinery/pkg/labels"
)

// kubernetesInstanceLabel identifies the component name
const kubernetesInstanceLabel = "app.kubernetes.io/instance"

// kubernetesNameLabel identifies the type of the component
// const kubernetesNameLabel = "app.kubernetes.io/name"

// kubernetesManagedByLabel identifies the manager of the component
const kubernetesManagedByLabel = "app.kubernetes.io/managed-by"

// kubernetesManagedByVersionLabel identifies the version of manager used to deploy the resource
const kubernetesManagedByVersionLabel = "app.kubernetes.io/managed-by-version"

// kubernetesPartOfLabel groups all object that belong to one application
const kubernetesPartOfLabel = "app.kubernetes.io/part-of"

// kubernetesStorageNameLabel is the label key that is applied to all storage resources
// that are created
const kubernetesStorageNameLabel = "app.kubernetes.io/storage-name"

// ComponentDevMode indicates the resource is deployed using dev command
const ComponentDevMode = "Dev"

// ComponentDeployMode indicates the resource is deployed using deploy command
const ComponentDeployMode = "Deploy"

// ComponentAnyMode is used to search resources deployed using either dev or deploy comamnd
const ComponentAnyMode = ""

// ComponentNoneName ...
const ComponentNoneName = "None"

// odoModeLabel ...
const odoModeLabel = "odo.dev/mode"

// odoProjectTypeAnnotation ...
const odoProjectTypeAnnotation = "odo.dev/project-type"

// app is the default name used when labeling
const app = "app"

const odoManager = "odo"

// devfileStorageLabel is the label key that is applied to all storage resources for devfile components
// that are created
const devfileStorageLabel = "storage-name"

const sourcePVCLabel = "odo-source-pvc"

// GetLabels return labels that should be applied to every object for given component in active application
// if you need labels to filter component then use GetSelector instead
func GetLabels(componentName string, applicationName string, mode string) map[string]string {
labels := getLabels(componentName, applicationName, mode, true)
return labels
}

// AddStorageInfo adds labels for storage resources
func AddStorageInfo(labels map[string]string, storageName string, isSourceVolume bool) {
labels[kubernetesStorageNameLabel] = storageName
labels["component"] = labels[kubernetesInstanceLabel]
labels[componentLabel] = labels[kubernetesInstanceLabel]
labels[devfileStorageLabel] = storageName
if isSourceVolume {
labels[sourcePVCLabel] = storageName
Expand Down Expand Up @@ -114,7 +68,7 @@ func SetProjectType(annotations map[string]string, value string) {
annotations[odoProjectTypeAnnotation] = value
}

// GetSelector is used for selection of resources which are a part of the given component
// GetSelector returns a selector string used for selection of resources which are part of the given component in given mode
func GetSelector(componentName string, applicationName string, mode string) string {
labels := getLabels(componentName, applicationName, mode, false)
return labels.String()
Expand Down Expand Up @@ -143,7 +97,7 @@ func getApplicationLabels(application string, additional bool) labels.Set {
kubernetesManagedByLabel: odoManager,
}
if additional {
labels[app] = application
labels[appLabel] = application
labels[kubernetesManagedByVersionLabel] = version.VERSION
}
return labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_getLabels(t *testing.T) {
},
want: labels.Set{
kubernetesPartOfLabel: "applicationame",
app: "applicationame",
appLabel: "applicationame",
kubernetesManagedByLabel: "odo",
kubernetesManagedByVersionLabel: version.VERSION,
kubernetesInstanceLabel: "componentname",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func SelectorBuilder() selectorBuilder {
}

func (o selectorBuilder) WithComponent(name string) selectorBuilder {
req, err := labels.NewRequirement("component", selection.Equals, []string{name})
req, err := labels.NewRequirement(componentLabel, selection.Equals, []string{name})
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/devfile/library/pkg/devfile/generator"
devfilefs "github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/ghodss/yaml"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
v1 "k8s.io/api/apps/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/redhat-developer/odo/pkg/libdevfile"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/log"

devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strings"

"github.com/devfile/library/pkg/devfile/generator"
"github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

"github.com/golang/mock/gomock"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/localConfigProvider"
"github.com/redhat-developer/odo/pkg/testingutil"
"github.com/redhat-developer/odo/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package storage
import (
"fmt"

"github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/localConfigProvider"
"github.com/redhat-developer/odo/pkg/log"
v1 "k8s.io/api/apps/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/localConfigProvider"
"github.com/redhat-developer/odo/pkg/util"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package storage
import (
"fmt"

odolabels "github.com/redhat-developer/odo/pkg/component/labels"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
"github.com/redhat-developer/odo/pkg/localConfigProvider"
"github.com/redhat-developer/odo/pkg/util"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testingutil/deployments.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testingutil

import (
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/testingutil/pods.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testingutil

import (
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testingutil/services.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testingutil

import (
odolabels "github.com/redhat-developer/odo/pkg/component/labels"
odolabels "github.com/redhat-developer/odo/pkg/labels"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down
Loading

0 comments on commit 4368eee

Please sign in to comment.