kptdev / kpt

Automate Kubernetes Configuration Editing
https://kpt.dev
Apache License 2.0
1.69k stars 225 forks source link

kpt is still checking for CRDs when annotation config.kubernetes.io/local-config: true #2767

Open shaunmitchellve opened 2 years ago

shaunmitchellve commented 2 years ago

Expected behavior

When adding the annotation config.kubernetes.io/local-config: "true" to the resource definition. Kpt would not check to see if the CRD is defined on the server.

Actual behavior

apiVersion: blueprints.cloud.google.com/v1alpha1
kind: ProjectServiceSet
metadata:
  name: gpc-project-services
  namespace: MYNAMESPACE
  annotations:
    cnrm.cloud.google.com/deletion-policy: true
    config.kubernetes.io/local-config: "true"
spec:
  services:
    - cloudapis.googleapis.com
    - clouddebugger.googleapis.com
  projectID: <MY-PROJECT>

The above resource uses a kpt function (gcr.io/kpt-fn/enable-gcp-services:v0.1.0) to create other resources (service.serviceusage.cnrm.cloud.google.com) that work perfectly fine.

$ kpt live apply

Error: 1 resource types could not be found in the cluster or as CRDs among the applied resources.

Resource types:
ProjectServiceSet.blueprints.cloud.google.com

I need to either delete the yaml file or change the extension of that file after kpt fn render to get past this error.

Information

Tried on kpt version: 1.0.0-beta.9 (Google Cloud Shell version) Also on: 1.0.0-beta.10, 1.0.0-beta.12

droot commented 2 years ago

@rquitales Is this something you can take a look at ?

/cc @mortent

rquitales commented 2 years ago

Hi @shaunmitchellve

It looks like you have an error in the yaml example you provided. The key and values of the annotation map must be a string.

In the example you provided, the value of the annotation cnrm.cloud.google.com/deletion-policy: true is parsed as a boolean instead of a string. This causes a silent error when we extract annotations from the unstructured object from upstream apimachinery's util functions, and no annotations are returned (ie. an empty map) here: https://github.com/GoogleContainerTools/kpt/blob/10868bd100b3547e665f608bdb43d51543ad3c2e/pkg/live/rgpath.go#L135

The custom resource will be ignored on apply, as expected, if you update the annotation to: cnrm.cloud.google.com/deletion-policy: "true"

shaunmitchellve commented 2 years ago

Thanks @rquitales. I added the quotes and local-config is now working as expected.

I wonder if not having it be a silent error but perhaps a warning might have helped me troubleshoot this.

Thanks again, going to close the issue.

morgante commented 2 years ago

Should we reopen this? I think it's common to forget the quotes and the error behavior is non-intuitive.