Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Make managed-by label value transparent #1894

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

nesmabadr
Copy link
Contributor

@nesmabadr nesmabadr commented Sep 26, 2024

Description

Changes proposed in this pull request:

  • Change managed by label to kyma instead of lifecycle-manager and declarative-v2 for SKR resources

Related issue(s)
Resolves #1821

@nesmabadr nesmabadr added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 26, 2024
@nesmabadr nesmabadr requested a review from a team as a code owner September 26, 2024 11:02
@kyma-bot kyma-bot added cla: yes Indicates the PR's author has signed the CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 26, 2024
@kyma-bot kyma-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 26, 2024
@kyma-bot kyma-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 26, 2024
@kyma-bot kyma-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 26, 2024
@kyma-bot kyma-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 26, 2024
@nesmabadr nesmabadr added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 26, 2024
@kyma-bot kyma-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 26, 2024
@kyma-bot kyma-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 26, 2024
Copy link
Contributor

@c-pius c-pius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the following resources that seem to missing the label:

  apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: "2024-09-30T11:21:49Z"
    name: skr-webhook-metrics
    namespace: kyma-system
    resourceVersion: "594"
    uid: 5d8db776-d102-404b-a46e-6fe17bf22f6f
  spec:
    clusterIP: 10.43.161.169
    clusterIPs:
    - 10.43.161.169
    internalTrafficPolicy: Cluster
    ipFamilies:
    - IPv4
    ipFamilyPolicy: SingleStack
    ports:
    - name: http-metrics
      port: 2112
      protocol: TCP
      targetPort: metrics-port
    selector:
      app: skr-webhook
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2024-09-30T11:21:49Z"
  name: skr-webhook-metrics
  namespace: kyma-system
  resourceVersion: "594"
  uid: 5d8db776-d102-404b-a46e-6fe17bf22f6f
spec:
  clusterIP: 10.43.161.169
  clusterIPs:
  - 10.43.161.169
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: http-metrics
    port: 2112
    protocol: TCP
    targetPort: metrics-port
  selector:
    app: skr-webhook
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
---
  apiVersion: v1
  items:
  - apiVersion: operator.kyma-project.io/v1alpha1
    kind: Sample
    metadata:
      creationTimestamp: "2024-09-30T11:26:00Z"
      finalizers:
      - sample.kyma-project.io/finalizer
      generation: 1
      name: sample-yaml
      namespace: kyma-system
      resourceVersion: "783"
      uid: d90013b9-e90c-4205-85dc-23122a1be6c6
    spec:
      resourceFilePath: ./module-data/yaml
    status:
      conditions:
      - lastTransitionTime: "2024-09-30T11:26:01Z"
        message: installation is ready and resources can be used
        observedGeneration: 1
        reason: Ready
        status: "True"
        type: Installation
      state: Ready
  kind: List
  metadata:
    resourceVersion: ""
---
  apiVersion: v1                             
  kind: ServiceAccount                       
    metadata:                                
    creationTimestamp: "2024-09-30T11:25:58Z"
    name: default                            
    namespace: template-operator-system      
    resourceVersion: "735"                   
    uid: 35585fc0-924a-4f37-85d2-ffc5a7cc288f
---

Do we also have documentation on the label that may need to be changed?

api/shared/operator_labels.go Outdated Show resolved Hide resolved
internal/controller/manifest/setup.go Show resolved Hide resolved
Comment on lines 76 to 82
labels := crdToApply.GetLabels()
if labels == nil {
labels = map[string]string{}
}
labels[shared.ManagedBy] = shared.KymaLabelValue
crdToApply.SetLabels(labels)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bugs me a bit that Go is so verbose here... Not a problem with your implementation but the language... Should we at least introduce a helper func that merges two sets of labels so that we don't have to the same logic 3 times?

Something like

func mergeMaps(map1, map2 map[string]string) map[string]string {
    mergedMap := make(map[string]string)

    for k, v := range map1 {
        mergedMap[k] = v
    }

    for k, v := range map2 {
        mergedMap[k] = v
    }

    return mergedMap
}

// usage

crdToApply.SetLabels(mergeMaps(crdToApply.GetLabels(), map[string]string{
	shared.ManagedBy: shared.KymaLabelValue,
}))

I also played around with maps.Copy std func but that one fails if the destination map is nil which could be the case for us. Ideally, we could also make the mergeMaps func generic instead of string string.

WDYT?

Comment on lines 217 to 222
labels := moduleTemplate.GetLabels()
if labels == nil {
labels = map[string]string{}
}
labels[shared.ManagedBy] = shared.KymaLabelValue
moduleTemplate.SetLabels(labels)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the map topic

Comment on lines 196 to 202
labels := deployment.GetLabels()
if labels == nil {
labels = make(map[string]string)
}
labels[shared.ManagedBy] = shared.KymaLabelValue
deployment.SetLabels(labels)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the map topic

Comment on lines 46 to +51
lbls := resource.GetLabels()
if lbls == nil {
lbls = make(map[string]string)
}
lbls[shared.WatchedByLabel] = shared.WatchedByLabelValue
lbls[shared.ManagedBy] = shared.ManagedByLabelValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this would be another +1 for the merge maps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make managed-by label more transparent
3 participants