From 25ed51b0269912dc9a25b65f307b5b1a94708f8a Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Mon, 1 Jan 2024 14:18:57 +0200 Subject: [PATCH 1/2] fix: destination namespace type change backwards compatibility --- api/v1/common.go | 23 ++++++++-- api/v1/zz_generated.deepcopy.go | 5 +++ config/deploy/crd.yaml | 76 ++++++++++++++++----------------- config/deploy/manifests.yaml | 76 ++++++++++++++++----------------- 4 files changed, 101 insertions(+), 79 deletions(-) diff --git a/api/v1/common.go b/api/v1/common.go index abe87ca4a..f5a2612f5 100644 --- a/api/v1/common.go +++ b/api/v1/common.go @@ -1,6 +1,7 @@ package v1 import ( + "encoding/json" "fmt" "io/fs" "net/url" @@ -347,8 +348,13 @@ type Description struct { Description string `yaml:"description,omitempty" json:"description,omitempty" template:"true"` // Name of the check Name string `yaml:"name" json:"name" template:"true"` - // Namespace of the check - Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"` + // TODO: namespace is a json.RawMessage for backwards compatibility when it used to be a resource selector + // can be removed in a few versions time + + // Namespace to insert the check into, if different to the namespace the canary is defined, e.g. + // +kubebuilder:validation:Schemaless + // +kubebuilder:validation:Type=string + Namespace json.RawMessage `yaml:"namespace,omitempty" json:"namespace,omitempty" jsonschema:"type=string"` // Icon for overwriting default icon on the dashboard Icon string `yaml:"icon,omitempty" json:"icon,omitempty" template:"true"` // Labels for the check @@ -383,7 +389,18 @@ func (d Description) GetName() string { } func (d Description) GetNamespace() string { - return d.Namespace + s := string(d.Namespace) + if s == "" || s == "{}" { + return "" + } + if !strings.HasPrefix(s, "{}") { + return s + } + var r types.ResourceSelector + if err := json.Unmarshal(d.Namespace, &r); err != nil { + return r.Name + } + return "" } func (d Description) GetLabels() map[string]string { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index f31058089..744d4e0d8 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1410,6 +1410,11 @@ func (in *DatabaseBackupCheck) DeepCopy() *DatabaseBackupCheck { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Description) DeepCopyInto(out *Description) { *out = *in + if in.Namespace != nil { + in, out := &in.Namespace, &out.Namespace + *out = make(json.RawMessage, len(*in)) + copy(*out, *in) + } if in.Labels != nil { in, out := &in.Labels, &out.Labels *out = make(Labels, len(*in)) diff --git a/config/deploy/crd.yaml b/config/deploy/crd.yaml index 72541719c..b717ee733 100644 --- a/config/deploy/crd.yaml +++ b/config/deploy/crd.yaml @@ -135,7 +135,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -447,7 +447,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: type: string @@ -678,7 +678,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -861,7 +861,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string organization: type: string @@ -1061,7 +1061,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -1235,7 +1235,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: type: string @@ -1404,7 +1404,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -1459,7 +1459,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: type: string @@ -1588,7 +1588,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string test: properties: @@ -1668,7 +1668,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string port: type: integer @@ -1824,7 +1824,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -1964,7 +1964,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -2073,7 +2073,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string scheme: type: string @@ -2209,7 +2209,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -2372,7 +2372,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -3065,7 +3065,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string script: description: Script can be a inline script or a path to a script that needs to be executed On windows executed via powershell and in darwin and linux executed using bash @@ -3385,7 +3385,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string path: description: Path to folder or object storage, e.g. `s3://`, `gcs://`, `/path/tp/folder` @@ -3712,7 +3712,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: description: Query to be executed. Please see https://github.com/askgitdev/askgit for more details regarding syntax @@ -3879,7 +3879,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string project: type: string @@ -4047,7 +4047,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string ntlm: description: NTLM when set to true will do authentication using NTLM v1 protocol @@ -4253,7 +4253,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string packetCount: type: integer @@ -4364,7 +4364,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string port: description: Port on which the server is running @@ -4456,7 +4456,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string spec: type: object @@ -4558,7 +4558,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string namespaceSelector: properties: @@ -4658,7 +4658,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -4803,7 +4803,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -4954,7 +4954,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5132,7 +5132,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5322,7 +5322,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string namespaceAnnotations: additionalProperties: @@ -5416,7 +5416,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5611,7 +5611,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string path: type: string @@ -5694,7 +5694,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5875,7 +5875,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -6046,7 +6046,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -6243,7 +6243,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: description: Password for the restic repository @@ -6437,7 +6437,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string objectPath: description: glob path to restrict matches to a subset @@ -6589,7 +6589,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string thresholdMillis: format: int64 @@ -6654,7 +6654,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string test: properties: diff --git a/config/deploy/manifests.yaml b/config/deploy/manifests.yaml index 6f4975e36..9b6020e03 100644 --- a/config/deploy/manifests.yaml +++ b/config/deploy/manifests.yaml @@ -134,7 +134,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -446,7 +446,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: type: string @@ -677,7 +677,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -860,7 +860,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string organization: type: string @@ -1060,7 +1060,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -1234,7 +1234,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: type: string @@ -1403,7 +1403,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -1458,7 +1458,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: type: string @@ -1587,7 +1587,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string test: properties: @@ -1667,7 +1667,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string port: type: integer @@ -1823,7 +1823,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -1963,7 +1963,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string transformDeleteStrategy: description: Transformed checks have a delete strategy on deletion they can either be marked healthy, unhealthy or left as is @@ -2072,7 +2072,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string scheme: type: string @@ -2208,7 +2208,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string region: type: string @@ -2371,7 +2371,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -3064,7 +3064,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string script: description: Script can be a inline script or a path to a script that needs to be executed On windows executed via powershell and in darwin and linux executed using bash @@ -3384,7 +3384,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string path: description: Path to folder or object storage, e.g. `s3://`, `gcs://`, `/path/tp/folder` @@ -3711,7 +3711,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string query: description: Query to be executed. Please see https://github.com/askgitdev/askgit for more details regarding syntax @@ -3878,7 +3878,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string project: type: string @@ -4046,7 +4046,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string ntlm: description: NTLM when set to true will do authentication using NTLM v1 protocol @@ -4252,7 +4252,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string packetCount: type: integer @@ -4363,7 +4363,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string port: description: Port on which the server is running @@ -4455,7 +4455,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string spec: type: object @@ -4557,7 +4557,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string namespaceSelector: properties: @@ -4657,7 +4657,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -4802,7 +4802,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -4953,7 +4953,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5131,7 +5131,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5321,7 +5321,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string namespaceAnnotations: additionalProperties: @@ -5415,7 +5415,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5610,7 +5610,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string path: type: string @@ -5693,7 +5693,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -5874,7 +5874,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -6045,7 +6045,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: properties: @@ -6242,7 +6242,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string password: description: Password for the restic repository @@ -6436,7 +6436,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string objectPath: description: glob path to restrict matches to a subset @@ -6588,7 +6588,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string thresholdMillis: format: int64 @@ -6653,7 +6653,7 @@ spec: description: Name of the check type: string namespace: - description: Namespace of the check + description: Namespace to insert the check into, if different to the namespace the canary is defined, e.g. type: string test: properties: From 1d2185ad9e99a2a7b38f29e3a614d02c3f14d4a0 Mon Sep 17 00:00:00 2001 From: Moshe Immerman Date: Mon, 1 Jan 2024 14:19:36 +0200 Subject: [PATCH 2/2] chore: remove unused flags + reduce logging --- cmd/root.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index b446b1194..4cba422ce 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,7 +16,6 @@ import ( "github.com/flanksource/commons/logger" "github.com/flanksource/duty" "github.com/flanksource/duty/context" - gomplate "github.com/flanksource/gomplate/v3" "github.com/spf13/cobra" "github.com/spf13/pflag" "go.opentelemetry.io/otel" @@ -48,16 +47,11 @@ func InitContext() (context.Context, error) { var Root = &cobra.Command{ Use: "canary-checker", PersistentPreRun: func(cmd *cobra.Command, args []string) { - canary.LogFail = logFail canary.LogPass = logPass logger.UseZap(cmd.Flags()) - for _, script := range sharedLibrary { - if err := gomplate.LoadSharedLibrary(script); err != nil { - logger.Errorf("Failed to load shared library %s: %v", script, err) - } - } + db.ConnectionString = readFromEnv(db.ConnectionString) if db.ConnectionString == "DB_URL" { db.ConnectionString = "" @@ -78,8 +72,6 @@ var Root = &cobra.Command{ var ( httpPort = 8080 publicEndpoint = "http://localhost:8080" - sharedLibrary []string - exposeEnv bool logPass, logFail bool otelcollectorURL string @@ -98,6 +90,8 @@ func ServerFlags(flags *pflag.FlagSet) { _ = flags.MarkDeprecated("dev", "") _ = flags.MarkDeprecated("push-servers", "") _ = flags.MarkDeprecated("pull-servers", "") + _ = flags.MarkDeprecated("expose-env", "") + _ = flags.MarkDeprecated("shared-library", "") flags.StringVar(&publicEndpoint, "public-endpoint", publicEndpoint, "Host on which the health dashboard is exposed. Could be used for generting-links, redirects etc.") flags.StringSliceVar(&runner.IncludeCanaries, "include-check", []string{}, "Run matching canaries - useful for debugging") @@ -141,10 +135,8 @@ func init() { Root.PersistentFlags().StringVar(&db.ConnectionString, "db", "DB_URL", "Connection string for the postgres database") Root.PersistentFlags().BoolVar(&db.RunMigrations, "db-migrations", false, "Run database migrations") Root.PersistentFlags().BoolVar(&db.DBMetrics, "db-metrics", false, "Expose db metrics") - Root.PersistentFlags().BoolVar(&logFail, "log-fail", true, "Log every failing check") + Root.PersistentFlags().BoolVar(&logFail, "log-fail", false, "Log every failing check") Root.PersistentFlags().BoolVar(&logPass, "log-pass", false, "Log every passing check") - Root.PersistentFlags().StringArrayVar(&sharedLibrary, "shared-library", []string{}, "Add javascript files to be shared by all javascript templates") - Root.PersistentFlags().BoolVar(&exposeEnv, "expose-env", false, "Expose environment variables for use in all templates. Note this has serious security implications with untrusted canaries") Root.AddCommand(Docs) Root.AddCommand(Run, Serve, Operator) Root.AddCommand(Serve, GoOffline)