-
Notifications
You must be signed in to change notification settings - Fork 23
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
Enable server-side diffs #314
Conversation
Signed-off-by: Mmadu Manasseh <[email protected]>
Temporary image available at |
Signed-off-by: Mmadu Manasseh <[email protected]>
Signed-off-by: Mmadu Manasseh <[email protected]>
5580aed
to
45c9d53
Compare
Mergecat's ReviewClick to read mergecats review!😼 Mergecat review of .github/workflows/on_pull-request_docs.yaml@@ -24,4 +24,4 @@ jobs:
run: ./earthly.sh +rebuild-docs
- name: verify that the checked in file has not changed
- run: ./hacks/exit-on-changed-files.sh "Please run './earthly +rebuild-docs' and commit the results to this PR"
+ run: ./hacks/exit-on-changed-files.sh "Please run './earthly.sh +rebuild-docs' and commit the results to this PR" Feedback & Suggestions:
😼 Mergecat review of cmd/root.go@@ -119,6 +119,10 @@ func init() {
newStringOpts().
withDefault("kubechecks again"))
+ boolFlag(flags, "server-side-diff", "Enable server-side diff.",
+ newBoolOpts().
+ withDefault(false))
+
panicIfError(viper.BindPFlags(flags))
setupLogOutput()
} Feedback & Suggestions:
😼 Mergecat review of localdev/kubechecks/values.yaml@@ -10,6 +10,7 @@ configMap:
KUBECHECKS_NAMESPACE: 'kubechecks'
KUBECHECKS_FALLBACK_K8S_VERSION: "1.25.0"
KUBECHECKS_SHOW_DEBUG_INFO: "true"
+ KUBECHECKS_VCS_TYPE: "gitlab"
# OTEL
KUBECHECKS_OTEL_COLLECTOR_PORT: "4317"
KUBECHECKS_OTEL_ENABLED: "false"
@@ -21,14 +22,16 @@ configMap:
# KUBECHECKS_SCHEMAS_LOCATION: https://github.com/zapier/kubecheck-schemas.git
KUBECHECKS_TIDY_OUTDATED_COMMENTS_MODE: "delete"
KUBECHECKS_ENABLE_CONFTEST: "false"
+ KUBECHECKS_SERVER_SIDE_DIFF: "true"
+ GRPC_ENFORCE_ALPN_ENABLED: false
deployment:
annotations:
reloader.stakater.com/auto: "true"
image:
- pullPolicy: Never
+ pullPolicy: IfNotPresent
name: "kubechecks"
tag: ""
Feedback & Suggestions:
😼 Mergecat review of pkg/config/config.go@@ -79,6 +79,7 @@ type ServerConfig struct {
MaxQueueSize int64 `mapstructure:"max-queue-size"`
MaxConcurrenctChecks int `mapstructure:"max-concurrenct-checks"`
ReplanCommentMessage string `mapstructure:"replan-comment-msg"`
+ ServerSideDiff bool `mapstructure:"server-side-diff"`
}
func New() (ServerConfig, error) {
@@ -115,6 +116,7 @@ func NewWithViper(v *viper.Viper) (ServerConfig, error) {
log.Info().Msgf("Webhook URL Prefix: %s", cfg.UrlPrefix)
log.Info().Msgf("VCS Type: %s", cfg.VcsType)
log.Info().Msgf("ArgoCD Namespace: %s", cfg.ArgoCDNamespace)
+ log.Info().Msgf("Server-Side Diff: %v", cfg.ServerSideDiff)
return cfg, nil
} Feedback & Suggestions:
😼 Mergecat review of docs/usage.md@@ -67,6 +67,7 @@ The full list of supported environment variables is described below:
|`KUBECHECKS_REPLAN_COMMENT_MSG`|comment message which re-triggers kubechecks on PR.|`kubechecks again`|
|`KUBECHECKS_REPO_REFRESH_INTERVAL`|Interval between static repo refreshes (for schemas and policies).|`5m`|
|`KUBECHECKS_SCHEMAS_LOCATION`|Sets schema locations to be used for every check request. Can be common paths inside the repos being checked or git urls in either git or http(s) format.|`[]`|
+|`KUBECHECKS_SERVER_SIDE_DIFF`|Enable server-side diff.|`false`|
|`KUBECHECKS_SHOW_DEBUG_INFO`|Set to true to print debug info to the footer of MR comments.|`false`|
|`KUBECHECKS_TIDY_OUTDATED_COMMENTS_MODE`|Sets the mode to use when tidying outdated comments. One of hide, delete.|`hide`|
|`KUBECHECKS_VCS_BASE_URL`|VCS base url, useful if self hosting gitlab, enterprise github, etc.|| Feedback & Suggestions:
😼 Mergecat review of pkg/argo_client/manifests.go@@ -11,7 +11,9 @@ import (
repoapiclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/reposerver/repository"
"github.com/argoproj/argo-cd/v2/util/git"
+ "github.com/argoproj/argo-cd/v2/util/manifeststream"
"github.com/ghodss/yaml"
+ grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/api/resource"
@@ -102,6 +104,48 @@ func (argo *ArgoClient) generateManifests(
)
}
+// adapted fromm https://github.com/argoproj/argo-cd/blob/d3ff9757c460ae1a6a11e1231251b5d27aadcdd1/cmd/argocd/commands/app.go#L894
+func (argo *ArgoClient) GetManifestsServerSide(ctx context.Context, name, tempRepoDir, changedAppFilePath string, app argoappv1.Application) ([]string, error) {
+ var err error
+
+ ctx, span := tracer.Start(ctx, "GetManifestsServerSide")
+ defer span.End()
+
+ log.Debug().Str("name", name).Msg("GetManifestsServerSide")
+
+ start := time.Now()
+ defer func() {
+ duration := time.Since(start)
+ getManifestsDuration.WithLabelValues(name).Observe(duration.Seconds())
+ }()
+
+ appCloser, appClient := argo.GetApplicationClient()
+ defer appCloser.Close()
+
+ client, err := appClient.GetManifestsWithFiles(ctx, grpc_retry.Disable())
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to get manifest client")
+ }
+ localIncludes := []string{"*"}
+ log.Debug().Str("name", name).Str("repo_path", tempRepoDir).Msg("sending application manifest query with files")
+
+ err = manifeststream.SendApplicationManifestQueryWithFiles(ctx, client, name, app.Namespace, tempRepoDir, localIncludes)
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to send manifest query")
+ }
+
+ res, err := client.CloseAndRecv()
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to receive manifest response")
+ }
+
+ if res.Manifests == nil {
+ return nil, nil
+ }
+ getManifestsSuccess.WithLabelValues(name).Inc()
+ return res.Manifests, nil
+}
+
func ConvertJsonToYamlManifests(jsonManifests []string) []string {
var manifests []string
for _, manifest := range jsonManifests { Feedback & Suggestions:
😼 Mergecat review of pkg/events/worker.go@@ -105,9 +105,15 @@ func (w *worker) processApp(ctx context.Context, app v1alpha1.Application) {
return
}
repoPath := repo.Directory
+ var jsonManifests []string
- logger.Debug().Str("repo_path", repoPath).Msg("Getting manifests")
- jsonManifests, err := w.ctr.ArgoClient.GetManifestsLocal(ctx, appName, repoPath, appPath, app)
+ if !w.ctr.Config.ServerSideDiff {
+ logger.Debug().Str("repo_path", repoPath).Msg("Getting manifests")
+ jsonManifests, err = w.ctr.ArgoClient.GetManifestsLocal(ctx, appName, repoPath, appPath, app)
+ } else {
+ logger.Debug().Str("repo_path", repoPath).Msg("Getting server-side manifests")
+ jsonManifests, err = w.ctr.ArgoClient.GetManifestsServerSide(ctx, appName, repoPath, appPath, app)
+ }
if err != nil {
logger.Error().Err(err).Msg("Unable to get manifests")
w.vcsNote.AddToAppMessage(ctx, appName, msg.Result{ Feedback & Suggestions:
Overall, the changes are well-structured and improve the flexibility of the manifest retrieval process. Keep up the good work! 👍 Dependency ReviewClick to read mergecats review!No suggestions found |
@@ -21,14 +22,16 @@ configMap: | |||
# KUBECHECKS_SCHEMAS_LOCATION: https://github.com/zapier/kubecheck-schemas.git | |||
KUBECHECKS_TIDY_OUTDATED_COMMENTS_MODE: "delete" | |||
KUBECHECKS_ENABLE_CONFTEST: "false" | |||
KUBECHECKS_SERVER_SIDE_DIFF: "true" | |||
GRPC_ENFORCE_ALPN_ENABLED: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting the error credentials: cannot check peer: missing selected ALPN property
, hence why I disabled this, for local. I don't know why it was breaking
Closed in favour of #298 |
This adds an option to send your manifests to the server for diffing