mirror of
https://github.com/kyverno/kyverno.git
synced 2025-01-20 18:52:16 +00:00
added condition for resource sync
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
This commit is contained in:
parent
45e95c2217
commit
92d9d634a3
2 changed files with 18 additions and 7 deletions
2
Makefile
2
Makefile
|
@ -79,7 +79,7 @@ kyverno: fmt vet
|
|||
docker-publish-kyverno: docker-build-kyverno docker-push-kyverno
|
||||
|
||||
docker-build-kyverno:
|
||||
@docker buildx build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --progress plane --platform linux/arm64,linux/amd64 --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS) --build-arg TAGS=$(TAGS)
|
||||
@docker build --file $(PWD)/$(KYVERNO_PATH)/Dockerfile --tag $(REPO)/$(KYVERNO_IMAGE):$(IMAGE_TAG) . --build-arg LD_FLAGS=$(LD_FLAGS)
|
||||
|
||||
docker-build-kyverno-local:
|
||||
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/$(KYVERNO_PATH)/kyverno -tags $(TAGS) -ldflags=$(LD_FLAGS) $(PWD)/$(KYVERNO_PATH)/main.go
|
||||
|
|
|
@ -321,6 +321,7 @@ func applyRule(log logr.Logger, client *dclient.Client, rule kyverno.Rule, resou
|
|||
|
||||
// build the resource template
|
||||
newResource := &unstructured.Unstructured{}
|
||||
newResourceOnlyLabel := &unstructured.Unstructured{}
|
||||
newResource.SetUnstructuredContent(rdata)
|
||||
newResource.SetName(genName)
|
||||
newResource.SetNamespace(genNamespace)
|
||||
|
@ -365,12 +366,22 @@ func applyRule(log logr.Logger, client *dclient.Client, rule kyverno.Rule, resou
|
|||
label["policy.kyverno.io/synchronize"] = "disable"
|
||||
}
|
||||
|
||||
logger.V(4).Info("updating label in existing resource")
|
||||
newResource.SetLabels(label)
|
||||
_, err := client.UpdateResource(genAPIVersion, genKind, genNamespace, newResource, false)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to update resource")
|
||||
return noGenResource, err
|
||||
if rule.Generation.Synchronize {
|
||||
logger.V(4).Info("updating existing resource")
|
||||
newResource.SetLabels(label)
|
||||
_, err := client.UpdateResource(genAPIVersion, genKind, genNamespace, newResource, false)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to update resource")
|
||||
return noGenResource, err
|
||||
}
|
||||
} else {
|
||||
logger.V(4).Info("updating label in existing resource")
|
||||
newResourceOnlyLabel.SetLabels(label)
|
||||
_, err := client.UpdateResource(genAPIVersion, genKind, genNamespace, newResource, false)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to update label in existing resource")
|
||||
return noGenResource, err
|
||||
}
|
||||
}
|
||||
logger.V(2).Info("updated generate target resource")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue