Skip to content

Commit

Permalink
add incluster kubectl client to test serverside with mutatation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwin93 committed Dec 5, 2024
1 parent 1092924 commit e1e94e4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/checks/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ import (
argodiff "github.com/argoproj/argo-cd/v2/util/argo/diff"
"github.com/argoproj/argo-cd/v2/util/argo/normalizers"
"github.com/argoproj/gitops-engine/pkg/diff"
gitOpsdiff "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"
kubeutil "github.com/argoproj/gitops-engine/pkg/utils/kube"
"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"

"github.com/zapier/kubechecks/pkg/checks"
"github.com/zapier/kubechecks/pkg/msg"
Expand Down Expand Up @@ -201,11 +204,32 @@ func generateDiff(ctx context.Context, request checks.Request, argoSettings *set
ignoreNormalizerOpts := normalizers.IgnoreNormalizerOpts{
JQExecutionTimeout: 1 * time.Second,
}
kubeCtl := &kube.KubectlCmd{
Log: log,
Tracer: tracing.NopTracer{},
}
config, err = rest.InClusterConfig()
if err != nil {
return diff.DiffResult{}, err
}
apiRes, _, err := kubeCtl.LoadOpenAPISchema(config)
if err != nil {
return diff.DiffResult{}, err
}
resources, _, errr := kubeCtl.ManageResources(config, apiRes)
if err != nil {
return diff.DiffResult{}, err
}
dryRunner := gitOpsdiff.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).
Build()
if err != nil {
telemetry.SetError(span, err, "Build Diff")
Expand Down

0 comments on commit e1e94e4

Please sign in to comment.