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

Updating ConfigMap always fail due to "_example" modified error #8211

Closed
nak3 opened this issue Jun 5, 2020 · 11 comments · Fixed by knative/pkg#1381 or #8221
Closed

Updating ConfigMap always fail due to "_example" modified error #8211

nak3 opened this issue Jun 5, 2020 · 11 comments · Fixed by knative/pkg#1381 or #8221
Assignees
Labels
area/API API objects and controllers kind/bug Categorizes issue or PR as related to a bug.

Comments

@nak3
Copy link
Contributor

nak3 commented Jun 5, 2020

Description

In what area(s)?

/area API

What version of Knative?

Build on top of 4aedf5f

Expected Behavior

$ kubectl patch configmap config-network -n knative-serving -p '{"data":{"autoTLS":"Disabled"}}'

should work.

Actual Behavior

$ kubectl patch configmap config-network -n knative-serving -p '{"data":{"autoTLS":"Disabled"}}'
Error from server (BadRequest): admission webhook "config.webhook.istio.networking.internal.knative.dev" denied the request: validation failed: "_example" modified, you likely wanted to create an unindented configuration

Steps to Reproduce the Problem

  • Update configmap like just run patch command:
$ kubectl patch configmap config-network -n knative-serving -p '{"data":{"autoTLS":"Disabled"}}'

or

$ kubectl edit configmap config-network -n knative-serving 

and add a new config in non-_example block field with correct indent.

@nak3 nak3 added the kind/bug Categorizes issue or PR as related to a bug. label Jun 5, 2020
@knative-prow-robot knative-prow-robot added the area/API API objects and controllers label Jun 5, 2020
@vagababov
Copy link
Contributor

I reproduce it easily.
I think there's difference in the two strings the parsers generate (because those are two different YAML parsers). I think a few spaces here and there or a \n is all that matters.

@vagababov
Copy link
Contributor

Ok, found it
/assign

@markusthoemmes
Copy link
Contributor

Ugh, sorry for missing this. My first version checked for this but I lost that in rewriting it to a go tool. My bad 👼

@vagababov
Copy link
Contributor

Mainly I think it's because we're using two different yaml parsers :| which is always inviting trouble in subtle differences :)

knative-prow-robot pushed a commit that referenced this issue Jun 5, 2020
@munjalpatel
Copy link

munjalpatel commented Jun 6, 2020

Hello,

I am running into this issue while trying to configure the domain as described here:
https://knative.dev/development/install/installing-istio/

image

$ kubectl patch configmap/config-domain \
        -n knative-serving \
        --type merge -p '{"data":{"localhost.xip.io":""}}'

Error from server (BadRequest): admission webhook
"config.webhook.istio.networking.internal.knative.dev" denied the request: 
validation failed:  "_example" modified, you likely wanted to create an 
unindented configuration

How do I proceed forward?

@vagababov
Copy link
Contributor

Did you update your serving?

@munjalpatel
Copy link

I am using the vision 0.15 as documented on the knative docs site. Since this is fairly new, I am sure I am not using the latest version. Which version should I be upgrading to?

@zzvara
Copy link

zzvara commented Mar 15, 2022

The same problem appears on knative 1.2.0:

{"level":"info","ts":"2022-03-15T08:31:00.443Z","logger":"controller.kustomization","msg":"Starting workers","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","worker count":4}
{"level":"info","ts":"2022-03-15T08:31:10.443Z","logger":"controller.kustomization","msg":"server-side apply completed","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"flux-system","namespace":"flux-system","output":{"CustomResourceDefinition/alerts.notification.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/buckets.source.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/gitrepositories.source.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/helmcharts.source.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/helmreleases.helm.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/helmrepositories.source.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/imagepolicies.image.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/imagerepositories.image.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/imageupdateautomations.image.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/knativeeventings.operator.knative.dev":"unchanged","CustomResourceDefinition/knativeservings.operator.knative.dev":"unchanged","CustomResourceDefinition/kustomizations.kustomize.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/providers.notification.toolkit.fluxcd.io":"unchanged","CustomResourceDefinition/receivers.notification.toolkit.fluxcd.io":"unchanged","Namespace/flux-system":"unchanged"}}
{"level":"error","ts":"2022-03-15T08:31:11.872Z","logger":"controller.kustomization","msg":"Reconciliation failed after 11.42867209s, next try in 10m0s","reconciler group":"kustomize.toolkit.fluxcd.io","reconciler kind":"Kustomization","name":"flux-system","namespace":"flux-system","revision":"master/2a7ae64191fa4e30882097f46d3c04f5b294b156","error":"ConfigMap/system/config-logging dry-run failed, reason: BadRequest, error: admission webhook \"config.webhook.serving.knative.dev\" denied the request: validation failed: the update modifies a key in \"_example\" which is probably not what you want. Instead, copy the respective setting to the top-level of the ConfigMap, directly below \"data\"\n","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.1/pkg/internal/controller/controller.go:114\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.1/pkg/internal/controller/controller.go:311\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.1/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.11.1/pkg/internal/controller/controller.go:227"}
{"level":"debug","ts":"2022-03-15T08:31:11.872Z","logger":"events","msg":"Warning","object":{"kind":"Kustomization","namespace":"flux-system","name":"flux-system","uid":"b36d31d3-66b3-4545-a9bc-b67a574df99d","apiVersion":"kustomize.toolkit.fluxcd.io/v1beta2","resourceVersion":"11670096"},"reason":"error","message":"ConfigMap/system/config-logging dry-run failed, reason: BadRequest, error: admission webhook \"config.webhook.serving.knative.dev\" denied the request: validation failed: the update modifies a key in \"_example\" which is probably not what you want. Instead, copy the respective setting to the top-level of the ConfigMap, directly below \"data\"\n"}

@zzvara
Copy link

zzvara commented Mar 30, 2022

The same problem appears with knative 1.3.1 installed as operator.

@dfsdevops
Copy link

dfsdevops commented Oct 18, 2022

I am on 1.7.2 and I can't figure out how to get around this issue. Whats the actual resolution here? I am trying to modify the ingress class and I cannot, not even if by deleting and recreating from the configMap. I'm not sure what it thinks I changed.

EDIT: ok, turns out a few weeks ago when I was messing with this I must have modified the initial config, and when I went to apply it from scratch it created the configMap before it created the validating webhook, therefore it was already "modified" from the example but I thought it was only my newer modifications that were breaking thing. I pulled the right example block from the upstream and fixed the issue.

@gabo1208
Copy link
Member

gabo1208 commented Feb 14, 2024

For anyone having this issue, this snippet can help yo redo your example checksum in case you need it:


import (
	"fmt"
	"hash/crc32"
	"os"
	"regexp"
	"strings"

	"gopkg.in/yaml.v2"
)

var (
	// Allows for normalizing by collapsing newlines.
	sequentialNewlines = regexp.MustCompile("(?:\r?\n)+")
)

type ConfigMap struct {
	Data map[string]string `json:"data,omitempty" protobuf:"bytes,2,rep,name=data"`
}

func Checksum(value string) string {
	return fmt.Sprintf("%08x", crc32.ChecksumIEEE([]byte(sequentialNewlines.ReplaceAllString(strings.TrimSpace(value), `\n`))))
}

func main() {
	contents, _ := os.ReadFile("./config/config-leader-election.yaml")
	var cm ConfigMap
	if err := yaml.Unmarshal(contents, &cm); err != nil {
		fmt.Println("cannot decode incoming new object:")
	}

	exampleData := cm.Data["_example"]
	chks := Checksum(exampleData)
	exampleChecksum := "a2f53e10"
	fmt.Println(chks, exampleChecksum)
}

wmfgerrit pushed a commit to wikimedia/operations-deployment-charts that referenced this issue Jul 5, 2024
While trying to update staging, I realized that there was a testing
setting on config-defaults that was applied manually, so I tried
to restore the original _example config but I ended up in:

knative/serving#8211

This seems something very brittle to rely on, the webhook validator
can potentially reject the config if we add new (real) values etc..
It never happened in the past, but I stumbled upon it so I'd vote
for removing the problem entirely to be safe.

Simply stripping the _example settings works, since the checksum
value stored in the annotation is not validated anymore. I think
that it is way better to avoid _example, we have always checked
upstream docs for new settings, it shouldn't be a big problem.
Also those examples can be consulted in the yaml files shipped
by old knative releases on github, so easily retrievable.

Bug: T368359
Change-Id: I558ed01eb44bf230e61fdf14cc8537ac941618a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/API API objects and controllers kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
8 participants