skaffold icon indicating copy to clipboard operation
skaffold copied to clipboard

[v2][REGRESSION] Need ability to do hooks in manifest section prior to rendering

Open spstarr opened this issue 3 years ago • 3 comments

Expected behavior

  • Able to perform actions pre-post render

Expected YAML allowed:

apiVersion: skaffold/v3alpha1
kind: Config
metadata:
  name: skaffold-myapp-demo
profiles:
  - name: standalone-dev
    manifests:
      kustomize:
        paths:
          - kustomize/overlays/dev
        buildArgs: ["--enable-alpha-plugins", "--enable-exec"]
        hooks:
          before:
           - host:
               command: ["sh", "-c", "(/workspace/source/kustomize/overlays/$DEPLOYMENT_ENVIRONMENT; /usr/bin/kustomize-inject-env)"]
    deploy:
      kubectl:
        flags:
          disableValidation: false
        #defaultNamespace: mynamespace-dev

Actual behavior

  • Functionality regression from v1.x, not able to perform actions prior to running kustomize

Information

  • Skaffold version: v2.0.0-beta1
  • Operating system: Linux
  • Installed via: skaffold.dev
  • Contents of skaffold.yaml:
apiVersion: skaffold/v3alpha1
kind: Config
metadata:
  name: skaffold-myapp-demo
profiles:
  - name: standalone-dev
    manifests:
      kustomize:
        paths:
          - kustomize/overlays/dev
        buildArgs: ["--enable-alpha-plugins", "--enable-exec"]
    deploy:
      kubectl:
        flags:
          disableValidation: false
        #defaultNamespace: mynamespace-dev
        hooks:
          before:
           - host:
               command: ["sh", "-c", "(/workspace/source/kustomize/overlays/$DEPLOYMENT_ENVIRONMENT; /usr/bin/kustomize-inject-env)"]

Steps to reproduce the behavior

$ SKAFFOLD_MODULE=skaffold-myapp-demo SKAFFOLD_PROFILE=standalone-dev skaffold2 render -f skaffold/dev/skaffold.yaml -v info
INFO[0000] Skaffold &{Version:v2.0.0-beta1 ConfigVersion:skaffold/v3alpha1 GitVersion: GitCommit:06ad0bd3d7bff1f53c6cd201f3f67b73435c95e8 BuildDate:2022-08-03T21:07:27Z GoVersion:go1.17 Compiler:gc Platform:linux/amd64 User:}  subtask=-1 task=DevLoop
INFO[0000] applying profile: standalone-dev              subtask=-1 task=DevLoop
INFO[0000] no values found in profile for field TagPolicy, using original config values  subtask=-1 task=DevLoop
INFO[0000] no values found in profile for field BuildType, using original config values  subtask=-1 task=DevLoop
INFO[0000] Using kubectl context: XXXXXXXX  subtask=-1 task=DevLoop
INFO[0000] Loaded Skaffold defaults from "/home/spstarr/.skaffold/config"  subtask=-1 task=DevLoop
INFO[0000] hydrated-dir does not exist, creating /build/myapp-demo/.kpt-pipeline  subtask=-1 task=DevLoop
INFO[0000] manifests hydration will take place in /build/myapp-demo/.kpt-pipeline  subtask=-1 task=DevLoop
INFO[0000] build concurrency set to default value of -1  subtask=-1 task=DevLoop
INFO[0000] Tags generated in 2.217µs                     subtask=-1 task=Build
INFO[0000] Starting render...                            subtask=-1 task=DevLoop

Invalid rendering, should be kustomize?

INFO[0000] rendering using kubectl                       subtask=0 task=Render

Seems like a typo :( and this error seems to be invalid, i dont see any namespace fields defined.. :confused:

namespace already set in the namesapce. remove/unset 'namespace' field in manifests and try again.

spstarr avatar Aug 04 '22 21:08 spstarr

Thanks @spstarr for the issue. Looking more into it, render was part of deploy and hence pre-deploy hooks ~ pre-render hooks. We don't have support of pre-render hooks right now which is what you are missing. Can you use after-build hooks instead? If that works, we will open an issue for skaffold fix to convert pre-deploy hooks to after-build This will execute the hooks before rendering.

Regarding,

Invalid rendering, should be kustomize?

INFO[0000] rendering using kubectl subtask=0 task=Render

Actually the rendering happens via kustomize build. It is just a ux issue. Sorry about the confusion.

Same for the namespace already set ... error.

tejal29 avatar Aug 04 '22 23:08 tejal29

In this case, yes I need pre-render hooks. I am using Skaffold as a 'CD' so not using skaffold build (in future maybe TBD)

Pre-render --> [Render] Kustomize --> [Deploy] kubectl

spstarr avatar Aug 05 '22 14:08 spstarr

+1 the likely solution here will be to support hooks in the manifests section (render phase). This wasn't considered initially but it makes sense that hooks will likely be desirable for the render phase and that our current changes are a regression for those using v1 pre-deploy hooks. For this example, this would mean adding support for something like the following:

# ...
    manifests:
      kustomize:
        paths:
          - kustomize/overlays/dev
        buildArgs: ["--enable-alpha-plugins", "--enable-exec"]
        hooks:
          before:
           - host:
                 command: ["sh", "-c", "(/workspace/source/kustomize/overlays/$DEPLOYMENT_ENVIRONMENT; /usr/bin/kustomize-inject-env)"]

aaron-prindle avatar Aug 05 '22 20:08 aaron-prindle