Skip to content

upgrade command add three-way-merge option - #304

Merged
mumoshu merged 1 commit into
databus23:masterfrom
luxurine:master
Jan 8, 2022
Merged

mumoshu merged 1 commit into
databus23:masterfrom
luxurine:master

Conversation

@luxurine

@luxurine luxurine commented Sep 2, 2021 •

Copy link
Copy Markdown
Contributor

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

Temikus commented Sep 21, 2021

Copy link
Copy Markdown

@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

stale Bot commented Jan 3, 2022

Copy link
Copy Markdown

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
Comment thread cmd/upgrade.go
return fmt.Errorf("Failed to render chart: %s", err)
}

if d.threeWayMerge {

Copy link
Copy Markdown
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?

@mumoshu mumoshu Jan 9, 2022 •

Copy link
Copy Markdown
Collaborator

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.

@mumoshu mumoshu left a comment

Copy link
Copy Markdown
Collaborator

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

dudicoco commented Jan 9, 2022 •

Copy link
Copy Markdown

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

mumoshu commented Jan 9, 2022

Copy link
Copy Markdown
Collaborator

Yeah maybe in coming weeks.

@mumoshu

mumoshu commented Jan 9, 2022

Copy link
Copy Markdown
Collaborator

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