Skip to content

Commit

Permalink
change labels to follow the standards
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilSharmaWe committed Jul 9, 2022
1 parent 0a60a3a commit 5741259
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ func (s *apiScaffolder) updateMainEventRecorder() error {
}

func (s *apiScaffolder) scafffoldControllerWithImage(scaffold *machinery.Scaffold) error {
imageSplit := strings.Split(s.image, ":")
controller := &controllers.Controller{ControllerRuntimeVersion: golangv3scaffolds.ControllerRuntimeVersion,
Image: s.image,
Image: s.image,
ImageTag: imageSplit[1],
}
if err := scaffold.Execute(
controller,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type Controller struct {

ControllerRuntimeVersion string

Image string
Image string
ImageTag string
}

// SetTemplateDefaults implements file.Template
Expand Down Expand Up @@ -279,8 +280,14 @@ func (r *{{ .Resource.Kind }}Reconciler) deploymentFor{{ .Resource.Kind }}({{ lo
// labelsFor{{ .Resource.Kind }} returns the labels for selecting the resources
// belonging to the given {{ .Resource.Kind }} CR name.
// Note that the labels follows the standards defined in: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
func labelsFor{{ .Resource.Kind }}(name string) map[string]string {
return map[string]string{"type": "{{ lower .Resource.Kind }}", "{{ lower .Resource.Kind }}_cr": name}
return map[string]string{"app.kubernetes.io/name": "{{ .Resource.Kind }}",
"app.kubernetes.io/instance": name,
"app.kubernetes.io/version": "{{ .ImageTag }}",
"app.kubernetes.io/part-of": "",
"app.kubernetes.io/created-by": "controller-manager",
}
}
// SetupWithManager sets up the controller with the Manager.
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/deployimage/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ func Run(kbc *utils.TestContext) {
}
return nil
}, time.Minute, time.Second).Should(Succeed())
By("getting memcached deploy by labels")
getMemcachedDeploymentName := func() string {
memcachedDeploymentName, err := kbc.Kubectl.Get(
false, "deployment",
//nolint: lll
"-l", "app.kubernetes.io/name=Memcached,app.kubernetes.io/instance=memcached-sample,app.kubernetes.io/version=1.4.36-alpine,app.kubernetes.io/created-by=controller-manager",
"-o", "jsonpath={..metadata.name}")
Expect(err).NotTo(HaveOccurred())
return memcachedDeploymentName
}
Eventually(getMemcachedDeploymentName, 2*time.Minute, time.Second).ShouldNot(BeEmpty())

}

func uncommentPodStandards(kbc *utils.TestContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ func (r *BusyboxReconciler) deploymentForBusybox(busybox *examplecomv1alpha1.Bus

// labelsForBusybox returns the labels for selecting the resources
// belonging to the given Busybox CR name.
// Note that the labels follows the standards defined in: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
func labelsForBusybox(name string) map[string]string {
return map[string]string{"type": "busybox", "busybox_cr": name}
return map[string]string{"app.kubernetes.io/name": "Busybox",
"app.kubernetes.io/instance": name,
"app.kubernetes.io/version": "busybox:1.28",
"app.kubernetes.io/part-of": "",
"app.kubernetes.io/created-by": "controller-manager",
}
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ func (r *MemcachedReconciler) deploymentForMemcached(memcached *examplecomv1alph

// labelsForMemcached returns the labels for selecting the resources
// belonging to the given Memcached CR name.
// Note that the labels follows the standards defined in: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
func labelsForMemcached(name string) map[string]string {
return map[string]string{"type": "memcached", "memcached_cr": name}
return map[string]string{"app.kubernetes.io/name": "Memcached",
"app.kubernetes.io/instance": name,
"app.kubernetes.io/version": "memcached:1.4.36-alpine",
"app.kubernetes.io/part-of": "",
"app.kubernetes.io/created-by": "controller-manager",
}
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ func (r *BusyboxReconciler) deploymentForBusybox(busybox *examplecomv1alpha1.Bus

// labelsForBusybox returns the labels for selecting the resources
// belonging to the given Busybox CR name.
// Note that the labels follows the standards defined in: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
func labelsForBusybox(name string) map[string]string {
return map[string]string{"type": "busybox", "busybox_cr": name}
return map[string]string{"app.kubernetes.io/name": "Busybox",
"app.kubernetes.io/instance": name,
"app.kubernetes.io/version": "busybox:1.28",
"app.kubernetes.io/part-of": "",
"app.kubernetes.io/created-by": "controller-manager",
}
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ func (r *MemcachedReconciler) deploymentForMemcached(memcached *examplecomv1alph

// labelsForMemcached returns the labels for selecting the resources
// belonging to the given Memcached CR name.
// Note that the labels follows the standards defined in: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
func labelsForMemcached(name string) map[string]string {
return map[string]string{"type": "memcached", "memcached_cr": name}
return map[string]string{"app.kubernetes.io/name": "Memcached",
"app.kubernetes.io/instance": name,
"app.kubernetes.io/version": "memcached:1.4.36-alpine",
"app.kubernetes.io/part-of": "",
"app.kubernetes.io/created-by": "controller-manager",
}
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit 5741259

Please sign in to comment.