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

Draft: Enable WithIgnoreMutationWebhook #319

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ require (
k8s.io/api v0.31.3
k8s.io/apiextensions-apiserver v0.31.2
k8s.io/apimachinery v0.31.3
k8s.io/client-go v0.31.3
k8s.io/client-go v1.5.2
k8s.io/klog/v2 v2.130.1
sigs.k8s.io/controller-runtime v0.19.3
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -294,7 +295,6 @@ require (
k8s.io/cli-runtime v0.31.3 // indirect
k8s.io/component-base v0.31.3 // indirect
k8s.io/component-helpers v0.31.3 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-aggregator v0.31.2 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/kubectl v0.31.2 // indirect
Expand Down
27 changes: 26 additions & 1 deletion pkg/checks/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import (
"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/argoproj/gitops-engine/pkg/sync/hook"
"github.com/argoproj/gitops-engine/pkg/sync/ignore"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"github.com/argoproj/gitops-engine/pkg/utils/tracing"
"github.com/ghodss/yaml"
"github.com/go-logr/zerologr"
"github.com/pmezard/go-difflib/difflib"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/klog/v2/textlogger"

"github.com/zapier/kubechecks/pkg/checks"
"github.com/zapier/kubechecks/pkg/gitops-engine/pkg/utils/kube"
"github.com/zapier/kubechecks/pkg/msg"
"github.com/zapier/kubechecks/telemetry"
)
Expand Down Expand Up @@ -201,11 +204,33 @@ func generateDiff(ctx context.Context, request checks.Request, argoSettings *set
ignoreNormalizerOpts := normalizers.IgnoreNormalizerOpts{
JQExecutionTimeout: 1 * time.Second,
}
kubeCtl := &kube.KubectlCmd{
Tracer: tracing.NopTracer{},
Log: textlogger.NewLogger(textlogger.NewConfig()),
}
config, err := rest.InClusterConfig()
if err != nil {
return diff.DiffResult{}, err
}
apiRes, _, err := kubeCtl.LoadOpenAPISchema(config)
if err != nil {
return diff.DiffResult{}, err
}
resources, _, err := kubeCtl.ManageResources(config, apiRes)
if err != nil {
return diff.DiffResult{}, err
}
dryRunner := diff.NewK8sServerSideDryRunner(resources)

diffConfig, err := argodiff.NewDiffConfigBuilder().
WithLogger(zerologr.New(&log.Logger)).
WithDiffSettings(request.App.Spec.IgnoreDifferences, overrides, ignoreAggregatedRoles, ignoreNormalizerOpts).
WithTracking(argoSettings.AppLabelKey, argoSettings.TrackingMethod).
WithNoCache().
WithIgnoreMutationWebhook(false).
WithServerSideDiff(true).
WithServerSideDryRunner(dryRunner).
WithManager("application/apply-patch").
Build()
if err != nil {
telemetry.SetError(span, err, "Build Diff")
Expand Down
26 changes: 26 additions & 0 deletions pkg/gitops-engine/pkg/utils/kube/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kube

import (
"github.com/argoproj/gitops-engine/pkg/utils/kube/scheme"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

func convertToVersionWithScheme(obj *unstructured.Unstructured, group string, version string) (*unstructured.Unstructured, error) {
s := scheme.Scheme
object, err := s.ConvertToVersion(obj, runtime.InternalGroupVersioner)
if err != nil {
return nil, err
}
unmarshalledObj, err := s.ConvertToVersion(object, schema.GroupVersion{Group: group, Version: version})
if err != nil {
return nil, err
}
unstrBody, err := runtime.DefaultUnstructuredConverter.ToUnstructured(unmarshalledObj)
if err != nil {
return nil, err
}
return &unstructured.Unstructured{Object: unstrBody}, nil
}
Loading
Loading