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

upgrade command add three-way-merge option #304

Merged
merged 1 commit into from
Jan 8, 2022

Conversation

luxurine
Copy link
Contributor

@luxurine luxurine commented Sep 2, 2021

upgrade command add three-way-merge option to show diff for actual state vs desired state #176

prepared resource for testing

1、last release:

---
# Source: base-app/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: base-app-go
  labels:
    app: base-app-go
    team: ops
    owner: somebody
    helm.sh/chart: base-app-1.0.0
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 1323
      targetPort: 1323
      protocol: TCP
      name: http-1323
  selector:
    app: base-app-go
---
# Source: base-app/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: base-app-go
  labels:
    app: base-app-go
    team: ops
    owner: somebody
    helm.sh/chart: base-app-1.0.0
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: base-app-go
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: base-app-go
        team: ops
        owner: somebody
        helm.sh/chart: base-app-1.0.0
        app.kubernetes.io/managed-by: Helm
    spec:
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      initContainers:
      containers:
        - name: base-app-go
          image: xxxxx
          imagePullPolicy: IfNotPresent
          ports:
            - name: http-1323
              containerPort: 1323
              protocol: TCP
          lifecycle:
            preStop:
              exec:
                command:
                  - '/bin/sh'
                  - '-c'
                  - 'sleep 5'
          livenessProbe:
            httpGet:
              path: /healthz
              port: 1323
            initialDelaySeconds: 10
            periodSeconds: 60
          readinessProbe:
            httpGet:
              path: /healthz
              port: 1323
            initialDelaySeconds: 10
            periodSeconds: 3
          volumeMounts:
            - mountPath: /etc/localtime
              name: tz-config
              readOnly: true
            - mountPath: /sock
              name: sock-files
          envFrom:
          env:
            - name: CLUSTER
              value: dev
            - name: COUNT
              value: "3"
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ""
          name: tz-config
        - emptyDir: {}
          name: sock-files

2、target release:

---
# Source: base-app/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: base-app-go
  labels:
    app: base-app-go
    team: ops
    owner: somebody
    helm.sh/chart: base-app-1.0.0
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 1323
      targetPort: 1323
      protocol: TCP
      name: http-1323
  selector:
    app: base-app-go
---
# Source: base-app/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: base-app-go
  labels:
    app: base-app-go
    team: ops
    owner: somebody
    helm.sh/chart: base-app-1.0.0
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: base-app-go
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: base-app-go
        team: ops
        owner: somebody
        helm.sh/chart: base-app-1.0.0
        app.kubernetes.io/managed-by: Helm
    spec:
      imagePullSecrets:
        - name: regcred
      serviceAccountName: default
      initContainers:
      containers:
        - name: base-app-go
          image: xxxxx
          imagePullPolicy: IfNotPresent
          ports:
            - name: http-1323
              containerPort: 1323
              protocol: TCP
          lifecycle:
            preStop:
              exec:
                command:
                  - '/bin/sh'
                  - '-c'
                  - 'sleep 5'
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 60
            tcpSocket:
              port: 1323
          readinessProbe:
            httpGet:
              path: /healthz
              port: 1323
            initialDelaySeconds: 10
            periodSeconds: 3
          volumeMounts:
            - mountPath: /etc/localtime
              name: tz-config
              readOnly: true
            - mountPath: /sock
              name: sock-files
          envFrom:
          env:
            - name: CLUSTER
              value: dev
            - name: COUNT
              value: "4"
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ""
          name: tz-config
        - emptyDir: {}
          name: sock-files

normal diff vs diff with --three-way-merge option

1、manual change:

  • preStop time from 5 to 10
  • delete readinessProbe
  • delete Service

2、normal diff output:

default, base-app-go, Deployment (apps) has changed:
...
                    - '-c'
                    - 'sleep 5'
            livenessProbe:
-             httpGet:
-               path: /healthz
-               port: 1323
              initialDelaySeconds: 10
              periodSeconds: 60
+             tcpSocket:
+               port: 1323
            readinessProbe:
              httpGet:
                path: /healthz
...
              - name: CLUSTER
                value: dev
              - name: COUNT
-               value: "3"
+               value: "4"
        volumes:
          - hostPath:
              path: /etc/localtime

3、diff output with --three-way-merge option:

default, base-app-go, Deployment (apps) has changed:
...
      meta.helm.sh/release-name: base-app-01
      meta.helm.sh/release-namespace: default
    creationTimestamp: "2021-09-01T06:29:39Z"
-   generation: 8
+   generation: 9
    labels:
      app: base-app-go
      app.kubernetes.io/managed-by: Helm
...
       - env:
          - name: CLUSTER
             value: dev
          - name: COUNT
-           value: "3"
+           value: "4"
          image: "xxxxx"
          imagePullPolicy: IfNotPresent
          lifecycle:
...
                command:
                - /bin/sh
                - -c
-               - sleep 10
+               - sleep 5
          livenessProbe:
            failureThreshold: 3
-           httpGet:
-             path: /healthz
-             port: 1323
-             scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 60
            successThreshold: 1
+           tcpSocket:
+             port: 1323
            timeoutSeconds: 1
          name: base-app-go
          ports:
          - containerPort: 1323
            name: http-1323
            protocol: TCP
+         readinessProbe:
+           failureThreshold: 3
+           httpGet:
+             path: /healthz
+             port: 1323
+             scheme: HTTP
+           initialDelaySeconds: 10
+           periodSeconds: 3
+           successThreshold: 1
+           timeoutSeconds: 1
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
...
default, base-app-go, Service (v1) has been added:
- 
+ apiVersion: v1
+ kind: Service
+ metadata:
+   labels:
+     app: base-app-go
+     app.kubernetes.io/managed-by: Helm
+     helm.sh/chart: base-app-1.0.0
+     owner: somebody
+     team: ops
+   name: base-app-go
+   namespace: default
+ spec:
+   ports:
+   - name: http-1323
+     port: 1323
+     protocol: TCP
+     targetPort: 1323
+   selector:
+     app: base-app-go
+   type: ClusterIP

inspired by https://github.com/bacongobbler/helm-patchdiff

@Temikus
Copy link

Temikus commented Sep 21, 2021

@databus23 @mumoshu can I humbly ask you folks to take a look? 🙏

This might be a step in the right direction to solve #176

@stale
Copy link

stale bot commented Jan 3, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 3, 2022
@mumoshu mumoshu removed the stale label Jan 8, 2022
@@ -169,6 +192,25 @@ func (d *diffCmd) runHelm3() error {
return fmt.Errorf("Failed to render chart: %s", err)
}

if d.threeWayMerge {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably L171-L193 doesn't need to be run when we enter the 3-way merge mode?

Copy link
Collaborator

@mumoshu mumoshu Jan 9, 2022

Choose a reason for hiding this comment

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

Nevermind. It turned out correct as we still render the chart at L190 to be used when building K8s objects at L207.

Copy link
Collaborator

@mumoshu mumoshu left a comment

Choose a reason for hiding this comment

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

I have one concern but this looks great for a starter. Thanks a lot for your patience and contribution!

@dudicoco
Copy link

dudicoco commented Jan 9, 2022

Thank you for this addition @luxurine and @mumoshu

When can we expect a new release which contains this change?

mumoshu added a commit that referenced this pull request Jan 9, 2022
This adds a dedicated envvar to enable the three-way-merge diff added in #304. It should be useful when you are using helm-diff from another command or script and you dont have ability to specify the --three-way-merge flag without modifying the command/script but you cant due to various reasons.
mumoshu added a commit that referenced this pull request Jan 9, 2022
This adds a dedicated envvar to enable the three-way-merge diff added in #304. It should be useful when you are using helm-diff from another command or script and you dont have ability to specify the --three-way-merge flag without modifying the command/script but you cant due to various reasons.
@mumoshu
Copy link
Collaborator

mumoshu commented Jan 9, 2022

Yeah maybe in coming weeks.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 9, 2022

FYI, I've added a feature to enable this via an envvar. See #336 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants