From 5e77b4d80041fa4a7933d20bb3ab581ff9a22fdd Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Tue, 17 Dec 2024 11:24:00 +0100 Subject: [PATCH 1/4] Add graphql id to http requests --- internal/api/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/api/client.go b/internal/api/client.go index c649d8f6..50935453 100644 --- a/internal/api/client.go +++ b/internal/api/client.go @@ -95,7 +95,11 @@ func (c *Client) MakeRequest(ctx context.Context, req *graphql.Request, resp *gr if err != nil { return err } - graphqlURL, err := c.Address().Parse("graphql") + opName := "unknown" + if req.OpName != "" { + opName = req.OpName + } + graphqlURL, err := c.Address().Parse(fmt.Sprintf("graphql?id=%s", opName)) if err != nil { return nil } From fbdc77bec33500e3fc749d69ae2c6bf3a134c3de Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Tue, 17 Dec 2024 11:24:34 +0100 Subject: [PATCH 2/4] Update test to not rely on external DNS resolution --- controllers/suite/resources/humioresources_controller_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/suite/resources/humioresources_controller_test.go b/controllers/suite/resources/humioresources_controller_test.go index 0f8d672b..ae581a6b 100644 --- a/controllers/suite/resources/humioresources_controller_test.go +++ b/controllers/suite/resources/humioresources_controller_test.go @@ -2313,7 +2313,7 @@ var _ = Describe("Humio Resources Controllers", func() { }, } - expectedSecretValue := "https://hooks.slack.com/services/T00000000/B00000000/YYYYYYYYYYYYYYYYYYYYYYYY" + expectedSecretValue := fmt.Sprintf("https://%s/services/T00000000/B00000000/YYYYYYYYYYYYYYYYYYYYYYYY", testService1.Name) secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: toCreateAction.Spec.SlackProperties.UrlSource.SecretKeyRef.LocalObjectReference.Name, @@ -2361,7 +2361,7 @@ var _ = Describe("Humio Resources Controllers", func() { Namespace: clusterKey.Namespace, } - expectedSecretValue := "https://hooks.slack.com/services/T00000000/B00000000/YYYYYYYYYYYYYYYYYYYYYYYY" + expectedSecretValue := fmt.Sprintf("https://%s/services/T00000000/B00000000/YYYYYYYYYYYYYYYYYYYYYYYY", testService1.Name) toCreateAction := &humiov1alpha1.HumioAction{ ObjectMeta: metav1.ObjectMeta{ Name: key.Name, From ca867542c3d69d4102571bd5b45a256ed54b92db Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Tue, 17 Dec 2024 11:25:20 +0100 Subject: [PATCH 3/4] Clean up the way diffs are printed --- controllers/humioaction_controller.go | 99 +++++++++---------- controllers/humioaggregatealert_controller.go | 35 ++++--- controllers/humioalert_controller.go | 31 +++--- controllers/humiofilteralert_controller.go | 29 +++--- controllers/humioingesttoken_controller.go | 19 ++-- controllers/humioparser_controller.go | 19 ++-- controllers/humiorepository_controller.go | 23 +++-- .../humioscheduledsearch_controller.go | 35 ++++--- controllers/humioview_controller.go | 19 ++-- docs/api.md | 5 + internal/helpers/helpers.go | 10 ++ 11 files changed, 165 insertions(+), 159 deletions(-) diff --git a/controllers/humioaction_controller.go b/controllers/humioaction_controller.go index 740524e9..38cb4b8c 100644 --- a/controllers/humioaction_controller.go +++ b/controllers/humioaction_controller.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "strings" "time" "github.com/go-logr/logr" @@ -181,9 +180,9 @@ func (r *HumioActionReconciler) reconcileHumioAction(ctx context.Context, client return reconcile.Result{}, r.logErrorAndReturn(err, "could not parse expected action") } - if asExpected, diff := actionAlreadyAsExpected(expectedAction, curAction); !asExpected { + if asExpected, diffKeysAndValues := actionAlreadyAsExpected(expectedAction, curAction); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) err = r.HumioClient.UpdateAction(ctx, client, req, ha) if err != nil { @@ -317,165 +316,165 @@ func (r *HumioActionReconciler) logErrorAndReturn(err error, msg string) error { // actionAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func actionAlreadyAsExpected(expectedAction humiographql.ActionDetails, currentAction humiographql.ActionDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func actionAlreadyAsExpected(expectedAction humiographql.ActionDetails, currentAction humiographql.ActionDetails) (bool, map[string]string) { + keyValues := map[string]string{} switch e := (expectedAction).(type) { case *humiographql.ActionDetailsEmailAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsEmailAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetRecipients(), e.GetRecipients()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.recipients=%q", e, diff)) + keyValues[fmt.Sprintf("%T.recipients", e)] = diff } if diff := cmp.Diff(c.GetSubjectTemplate(), e.GetSubjectTemplate()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.subjectTemplate()=%q", e, diff)) + keyValues[fmt.Sprintf("%T.subjectTemplate", e)] = diff } if diff := cmp.Diff(c.GetEmailBodyTemplate(), e.GetEmailBodyTemplate()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.bodyTemplate=%q", e, diff)) + keyValues[fmt.Sprintf("%T.bodyTemplate", e)] = diff } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsHumioRepoAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsHumioRepoAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetIngestToken(), e.GetIngestToken()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.ingestToken=%q", e, "")) + keyValues[fmt.Sprintf("%T.ingestToken", e)] = "" } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsOpsGenieAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsOpsGenieAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetApiUrl(), e.GetApiUrl()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.apiUrl=%q", e, diff)) + keyValues[fmt.Sprintf("%T.apiUrl", e)] = diff } if diff := cmp.Diff(c.GetGenieKey(), e.GetGenieKey()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.genieKey=%q", e, "")) + keyValues[fmt.Sprintf("%T.genieKey", e)] = "" } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsPagerDutyAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsPagerDutyAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetRoutingKey(), e.GetRoutingKey()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.apiUrl=%q", e, "")) + keyValues[fmt.Sprintf("%T.apiUrl", e)] = "" } if diff := cmp.Diff(c.GetSeverity(), e.GetSeverity()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.genieKey=%q", e, diff)) + keyValues[fmt.Sprintf("%T.genieKey", e)] = diff } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsSlackAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsSlackAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetFields(), e.GetFields()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.fields=%q", e, diff)) + keyValues[fmt.Sprintf("%T.fields", e)] = diff } if diff := cmp.Diff(c.GetUrl(), e.GetUrl()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.url=%q", e, "")) + keyValues[fmt.Sprintf("%T.url", e)] = "" } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsSlackPostMessageAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsSlackPostMessageAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetApiToken(), e.GetApiToken()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.apiToken=%q", e, "")) + keyValues[fmt.Sprintf("%T.apiToken", e)] = "" } if diff := cmp.Diff(c.GetChannels(), e.GetChannels()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.channels=%q", e, diff)) + keyValues[fmt.Sprintf("%T.channels", e)] = diff } if diff := cmp.Diff(c.GetFields(), e.GetFields()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.fields=%q", e, diff)) + keyValues[fmt.Sprintf("%T.fields", e)] = diff } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsVictorOpsAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsVictorOpsAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetMessageType(), e.GetMessageType()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.messageType=%q", e, diff)) + keyValues[fmt.Sprintf("%T.messageType", e)] = diff } if diff := cmp.Diff(c.GetNotifyUrl(), e.GetNotifyUrl()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.notifyUrl=%q", e, "")) + keyValues[fmt.Sprintf("%T.notifyUrl", e)] = "" } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } case *humiographql.ActionDetailsWebhookAction: switch c := (currentAction).(type) { case *humiographql.ActionDetailsWebhookAction: if diff := cmp.Diff(c.GetName(), e.GetName()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.name=%q", e, diff)) + keyValues[fmt.Sprintf("%T.name", e)] = diff } if diff := cmp.Diff(c.GetWebhookBodyTemplate(), e.GetWebhookBodyTemplate()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.bodyTemplate=%q", e, diff)) + keyValues[fmt.Sprintf("%T.bodyTemplate", e)] = diff } if diff := cmp.Diff(c.GetHeaders(), e.GetHeaders()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.headers=%q", e, "")) + keyValues[fmt.Sprintf("%T.headers", e)] = "" } if diff := cmp.Diff(c.GetMethod(), e.GetMethod()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.method=%q", e, diff)) + keyValues[fmt.Sprintf("%T.method", e)] = diff } if diff := cmp.Diff(c.GetUrl(), e.GetUrl()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.url=%q", e, "")) + keyValues[fmt.Sprintf("%T.url", e)] = "" } if diff := cmp.Diff(c.GetIgnoreSSL(), e.GetIgnoreSSL()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.ignoreSSL=%q", e, diff)) + keyValues[fmt.Sprintf("%T.ignoreSSL", e)] = diff } if diff := cmp.Diff(c.GetUseProxy(), e.GetUseProxy()); diff != "" { - diffs = append(diffs, fmt.Sprintf("%T.useProxy=%q", e, diff)) + keyValues[fmt.Sprintf("%T.useProxy", e)] = diff } default: - diffs = append(diffs, fmt.Sprintf("expected type %T but current is %T", e, c)) + keyValues["wrongType"] = fmt.Sprintf("expected type %T but current is %T", e, c) } } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioaggregatealert_controller.go b/controllers/humioaggregatealert_controller.go index 94cc6b8a..49830f4d 100644 --- a/controllers/humioaggregatealert_controller.go +++ b/controllers/humioaggregatealert_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -178,9 +177,9 @@ func (r *HumioAggregateAlertReconciler) reconcileHumioAggregateAlert(ctx context return reconcile.Result{}, r.logErrorAndReturn(err, "could not validate actions for aggregate alert") } - if asExpected, diff := aggregateAlertAlreadyAsExpected(haa, curAggregateAlert); !asExpected { + if asExpected, diffKeysAndValues := aggregateAlertAlreadyAsExpected(haa, curAggregateAlert); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) updateErr := r.HumioClient.UpdateAggregateAlert(ctx, client, req, haa) if updateErr != nil { @@ -219,49 +218,49 @@ func (r *HumioAggregateAlertReconciler) logErrorAndReturn(err error, msg string) // aggregateAlertAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func aggregateAlertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioAggregateAlert, fromGraphQL *humiographql.AggregateAlertDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func aggregateAlertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioAggregateAlert, fromGraphQL *humiographql.AggregateAlertDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } labelsFromGraphQL := fromGraphQL.GetLabels() sort.Strings(labelsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Labels) if diff := cmp.Diff(labelsFromGraphQL, fromKubernetesCustomResource.Spec.Labels); diff != "" { - diffs = append(diffs, fmt.Sprintf("labels=%q", diff)) + keyValues["labels"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleField(), fromKubernetesCustomResource.Spec.ThrottleField); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleField=%q", diff)) + keyValues["throttleField"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleTimeSeconds(), fromKubernetesCustomResource.Spec.ThrottleTimeSeconds); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleTimeSeconds=%q", diff)) + keyValues["throttleTimeSeconds"] = diff } actionsFromGraphQL := humioapi.GetActionNames(fromGraphQL.GetActions()) sort.Strings(actionsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Actions) if diff := cmp.Diff(actionsFromGraphQL, fromKubernetesCustomResource.Spec.Actions); diff != "" { - diffs = append(diffs, fmt.Sprintf("actions=%q", diff)) + keyValues["actions"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryTimestampType(), humiographql.QueryTimestampType(fromKubernetesCustomResource.Spec.QueryTimestampType)); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryTimestampType=%q", diff)) + keyValues["queryTimestampType"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryString(), fromKubernetesCustomResource.Spec.QueryString); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryString=%q", diff)) + keyValues["queryString"] = diff } if diff := cmp.Diff(fromGraphQL.GetTriggerMode(), humiographql.TriggerMode(fromKubernetesCustomResource.Spec.TriggerMode)); diff != "" { - diffs = append(diffs, fmt.Sprintf("triggerMode=%q", diff)) + keyValues["triggerMode"] = diff } if diff := cmp.Diff(fromGraphQL.GetSearchIntervalSeconds(), int64(fromKubernetesCustomResource.Spec.SearchIntervalSeconds)); diff != "" { - diffs = append(diffs, fmt.Sprintf("searchIntervalSeconds=%q", diff)) + keyValues["searchIntervalSeconds"] = diff } if diff := cmp.Diff(fromGraphQL.GetEnabled(), fromKubernetesCustomResource.Spec.Enabled); diff != "" { - diffs = append(diffs, fmt.Sprintf("enabled=%q", diff)) + keyValues["enabled"] = diff } if !humioapi.QueryOwnershipIsOrganizationOwnership(fromGraphQL.GetQueryOwnership()) { - diffs = append(diffs, fmt.Sprintf("queryOwnership=%+v", fromGraphQL.GetQueryOwnership())) + keyValues["queryOwnership"] = fmt.Sprintf("%+v", fromGraphQL.GetQueryOwnership()) } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioalert_controller.go b/controllers/humioalert_controller.go index aeb98d5d..9bfd527a 100644 --- a/controllers/humioalert_controller.go +++ b/controllers/humioalert_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -165,9 +164,9 @@ func (r *HumioAlertReconciler) reconcileHumioAlert(ctx context.Context, client * r.Log.Info("Checking if alert needs to be updated") - if asExpected, diff := alertAlreadyAsExpected(ha, curAlert); !asExpected { + if asExpected, diffKeysAndValues := alertAlreadyAsExpected(ha, curAlert); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) err = r.HumioClient.UpdateAlert(ctx, client, req, ha) if err != nil { @@ -205,43 +204,43 @@ func (r *HumioAlertReconciler) logErrorAndReturn(err error, msg string) error { // alertAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func alertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioAlert, fromGraphQL *humiographql.AlertDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func alertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioAlert, fromGraphQL *humiographql.AlertDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } labelsFromGraphQL := fromGraphQL.GetLabels() sort.Strings(labelsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Labels) if diff := cmp.Diff(labelsFromGraphQL, fromKubernetesCustomResource.Spec.Labels); diff != "" { - diffs = append(diffs, fmt.Sprintf("labels=%q", diff)) + keyValues["labels"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleField(), fromKubernetesCustomResource.Spec.ThrottleField); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleField=%q", diff)) + keyValues["throttleField"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleTimeMillis(), int64(fromKubernetesCustomResource.Spec.ThrottleTimeMillis)); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleTimeMillis=%q", diff)) + keyValues["throttleTimeMillis"] = diff } actionsFromGraphQL := humioapi.GetActionNames(fromGraphQL.GetActionsV2()) sort.Strings(actionsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Actions) if diff := cmp.Diff(actionsFromGraphQL, fromKubernetesCustomResource.Spec.Actions); diff != "" { - diffs = append(diffs, fmt.Sprintf("actions=%q", diff)) + keyValues["actions"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryString(), fromKubernetesCustomResource.Spec.Query.QueryString); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryString=%q", diff)) + keyValues["queryString"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryStart(), fromKubernetesCustomResource.Spec.Query.Start); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryString=%q", diff)) + keyValues["queryString"] = diff } if diff := cmp.Diff(fromGraphQL.GetEnabled(), !fromKubernetesCustomResource.Spec.Silenced); diff != "" { - diffs = append(diffs, fmt.Sprintf("enabled=%q", diff)) + keyValues["enabled"] = diff } if !humioapi.QueryOwnershipIsOrganizationOwnership(fromGraphQL.GetQueryOwnership()) { - diffs = append(diffs, fmt.Sprintf("queryOwnership=%+v", fromGraphQL.GetQueryOwnership())) + keyValues["queryOwnership"] = fmt.Sprintf("%+v", fromGraphQL.GetQueryOwnership()) } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humiofilteralert_controller.go b/controllers/humiofilteralert_controller.go index 9a9c2121..429bae2f 100644 --- a/controllers/humiofilteralert_controller.go +++ b/controllers/humiofilteralert_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -176,9 +175,9 @@ func (r *HumioFilterAlertReconciler) reconcileHumioFilterAlert(ctx context.Conte return reconcile.Result{}, r.logErrorAndReturn(err, "could not get action id mapping") } - if asExpected, diff := filterAlertAlreadyAsExpected(hfa, curFilterAlert); !asExpected { + if asExpected, diffKeysAndValues := filterAlertAlreadyAsExpected(hfa, curFilterAlert); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) updateErr := r.HumioClient.UpdateFilterAlert(ctx, client, req, hfa) if updateErr != nil { @@ -216,40 +215,40 @@ func (r *HumioFilterAlertReconciler) logErrorAndReturn(err error, msg string) er // filterAlertAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func filterAlertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioFilterAlert, fromGraphQL *humiographql.FilterAlertDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func filterAlertAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioFilterAlert, fromGraphQL *humiographql.FilterAlertDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } labelsFromGraphQL := fromGraphQL.GetLabels() sort.Strings(labelsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Labels) if diff := cmp.Diff(labelsFromGraphQL, fromKubernetesCustomResource.Spec.Labels); diff != "" { - diffs = append(diffs, fmt.Sprintf("labels=%q", diff)) + keyValues["labels"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleField(), fromKubernetesCustomResource.Spec.ThrottleField); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleField=%q", diff)) + keyValues["throttleField"] = diff } if diff := cmp.Diff(fromGraphQL.GetThrottleTimeSeconds(), helpers.Int64Ptr(int64(fromKubernetesCustomResource.Spec.ThrottleTimeSeconds))); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleTimeSeconds=%q", diff)) + keyValues["throttleTimeSeconds"] = diff } actionsFromGraphQL := humioapi.GetActionNames(fromGraphQL.GetActions()) sort.Strings(actionsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Actions) if diff := cmp.Diff(actionsFromGraphQL, fromKubernetesCustomResource.Spec.Actions); diff != "" { - diffs = append(diffs, fmt.Sprintf("actions=%q", diff)) + keyValues["actions"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryString(), fromKubernetesCustomResource.Spec.QueryString); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryString=%q", diff)) + keyValues["queryString"] = diff } if diff := cmp.Diff(fromGraphQL.GetEnabled(), fromKubernetesCustomResource.Spec.Enabled); diff != "" { - diffs = append(diffs, fmt.Sprintf("enabled=%q", diff)) + keyValues["enabled"] = diff } if !humioapi.QueryOwnershipIsOrganizationOwnership(fromGraphQL.GetQueryOwnership()) { - diffs = append(diffs, fmt.Sprintf("queryOwnership=%+v", fromGraphQL.GetQueryOwnership())) + keyValues["queryOwnership"] = fmt.Sprintf("%+v", fromGraphQL.GetQueryOwnership()) } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioingesttoken_controller.go b/controllers/humioingesttoken_controller.go index 3b3d989f..f10f24df 100644 --- a/controllers/humioingesttoken_controller.go +++ b/controllers/humioingesttoken_controller.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "strings" "time" "github.com/go-logr/logr" @@ -158,9 +157,9 @@ func (r *HumioIngestTokenReconciler) Reconcile(ctx context.Context, req ctrl.Req return reconcile.Result{}, r.logErrorAndReturn(err, "could not check if ingest token exists") } - if asExpected, diff := ingestTokenAlreadyAsExpected(hit, curToken); !asExpected { + if asExpected, diffKeysAndValues := ingestTokenAlreadyAsExpected(hit, curToken); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) err = r.HumioClient.UpdateIngestToken(ctx, humioHttpClient, req, hit) if err != nil { @@ -269,26 +268,26 @@ func (r *HumioIngestTokenReconciler) logErrorAndReturn(err error, msg string) er // ingestTokenAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func ingestTokenAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioIngestToken, fromGraphQL *humiographql.IngestTokenDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func ingestTokenAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioIngestToken, fromGraphQL *humiographql.IngestTokenDetails) (bool, map[string]string) { + keyValues := map[string]string{} // Expects a parser assigned, but none found if fromGraphQL.GetParser() == nil && fromKubernetesCustomResource.Spec.ParserName != nil { - diffs = append(diffs, fmt.Sprintf("shouldAssignParser=%q", *fromKubernetesCustomResource.Spec.ParserName)) + keyValues["shouldAssignParser"] = *fromKubernetesCustomResource.Spec.ParserName } // Expects no parser assigned, but found one if fromGraphQL.GetParser() != nil && fromKubernetesCustomResource.Spec.ParserName == nil { - diffs = append(diffs, fmt.Sprintf("shouldUnassignParser=%q", fromGraphQL.GetParser().GetName())) + keyValues["shouldUnassignParser"] = fromGraphQL.GetParser().GetName() } // Parser already assigned, but not the one we expected if fromGraphQL.GetParser() != nil && fromKubernetesCustomResource.Spec.ParserName != nil { if diff := cmp.Diff(fromGraphQL.GetParser().GetName(), *fromKubernetesCustomResource.Spec.ParserName); diff != "" { - diffs = append(diffs, fmt.Sprintf("parserName=%q", diff)) + keyValues["parserName"] = diff } } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioparser_controller.go b/controllers/humioparser_controller.go index 35299f10..e1908174 100644 --- a/controllers/humioparser_controller.go +++ b/controllers/humioparser_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -156,9 +155,9 @@ func (r *HumioParserReconciler) Reconcile(ctx context.Context, req ctrl.Request) return reconcile.Result{}, r.logErrorAndReturn(err, "could not check if parser exists") } - if asExpected, diff := parserAlreadyAsExpected(hp, curParser); !asExpected { + if asExpected, diffKeysAndValues := parserAlreadyAsExpected(hp, curParser); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) err = r.HumioClient.UpdateParser(ctx, humioHttpClient, req, hp) if err != nil { @@ -222,22 +221,22 @@ func (r *HumioParserReconciler) logErrorAndReturn(err error, msg string) error { // parserAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func parserAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioParser, fromGraphQL *humiographql.ParserDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func parserAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioParser, fromGraphQL *humiographql.ParserDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetScript(), &fromKubernetesCustomResource.Spec.ParserScript); diff != "" { - diffs = append(diffs, fmt.Sprintf("parserScript=%q", diff)) + keyValues["parserScript"] = diff } tagFieldsFromGraphQL := fromGraphQL.GetFieldsToTag() sort.Strings(tagFieldsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.TagFields) if diff := cmp.Diff(tagFieldsFromGraphQL, fromKubernetesCustomResource.Spec.TagFields); diff != "" { - diffs = append(diffs, fmt.Sprintf("tagFields=%q", diff)) + keyValues["tagFields"] = diff } if diff := cmp.Diff(fromGraphQL.GetTestCases(), humioapi.TestDataToParserDetailsTestCasesParserTestCase(fromKubernetesCustomResource.Spec.TestData)); diff != "" { - diffs = append(diffs, fmt.Sprintf("testData=%q", diff)) + keyValues["testData"] = diff } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humiorepository_controller.go b/controllers/humiorepository_controller.go index e8812fee..f50865fc 100644 --- a/controllers/humiorepository_controller.go +++ b/controllers/humiorepository_controller.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -155,9 +154,9 @@ func (r *HumioRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Requ return reconcile.Result{}, r.logErrorAndReturn(err, "could not check if repository exists") } - if asExpected, diff := repositoryAlreadyAsExpected(hr, curRepository); !asExpected { + if asExpected, diffKeysAndValues := repositoryAlreadyAsExpected(hr, curRepository); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) err = r.HumioClient.UpdateRepository(ctx, humioHttpClient, req, hr) if err != nil { @@ -221,25 +220,25 @@ func (r *HumioRepositoryReconciler) logErrorAndReturn(err error, msg string) err // repositoryAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func repositoryAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioRepository, fromGraphQL *humiographql.RepositoryDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func repositoryAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioRepository, fromGraphQL *humiographql.RepositoryDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } if diff := cmp.Diff(fromGraphQL.GetTimeBasedRetention(), helpers.Int32PtrToFloat64Ptr(fromKubernetesCustomResource.Spec.Retention.TimeInDays)); diff != "" { - diffs = append(diffs, fmt.Sprintf("timeInDays=%q", diff)) + keyValues["timeInDays"] = diff } if diff := cmp.Diff(fromGraphQL.GetIngestSizeBasedRetention(), helpers.Int32PtrToFloat64Ptr(fromKubernetesCustomResource.Spec.Retention.IngestSizeInGB)); diff != "" { - diffs = append(diffs, fmt.Sprintf("ingestSizeInGB=%q", diff)) + keyValues["ingestSizeInGB"] = diff } if diff := cmp.Diff(fromGraphQL.GetStorageSizeBasedRetention(), helpers.Int32PtrToFloat64Ptr(fromKubernetesCustomResource.Spec.Retention.StorageSizeInGB)); diff != "" { - diffs = append(diffs, fmt.Sprintf("storageSizeInGB=%q", diff)) + keyValues["storageSizeInGB"] = diff } if diff := cmp.Diff(fromGraphQL.GetAutomaticSearch(), helpers.BoolTrue(fromKubernetesCustomResource.Spec.AutomaticSearch)); diff != "" { - diffs = append(diffs, fmt.Sprintf("automaticSearch=%q", diff)) + keyValues["automaticSearch"] = diff } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioscheduledsearch_controller.go b/controllers/humioscheduledsearch_controller.go index dd7da65c..81a2f2d6 100644 --- a/controllers/humioscheduledsearch_controller.go +++ b/controllers/humioscheduledsearch_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/google/go-cmp/cmp" @@ -165,9 +164,9 @@ func (r *HumioScheduledSearchReconciler) reconcileHumioScheduledSearch(ctx conte return reconcile.Result{}, r.logErrorAndReturn(err, "could not get action id mapping") } - if asExpected, diff := scheduledSearchAlreadyAsExpected(hss, curScheduledSearch); !asExpected { + if asExpected, diffKeysAndValues := scheduledSearchAlreadyAsExpected(hss, curScheduledSearch); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) updateErr := r.HumioClient.UpdateScheduledSearch(ctx, client, req, hss) if updateErr != nil { @@ -205,49 +204,49 @@ func (r *HumioScheduledSearchReconciler) logErrorAndReturn(err error, msg string // scheduledSearchAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func scheduledSearchAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioScheduledSearch, fromGraphQL *humiographql.ScheduledSearchDetails) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func scheduledSearchAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioScheduledSearch, fromGraphQL *humiographql.ScheduledSearchDetails) (bool, map[string]string) { + keyValues := map[string]string{} if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } labelsFromGraphQL := fromGraphQL.GetLabels() sort.Strings(labelsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Labels) if diff := cmp.Diff(labelsFromGraphQL, fromKubernetesCustomResource.Spec.Labels); diff != "" { - diffs = append(diffs, fmt.Sprintf("labels=%q", diff)) + keyValues["labels"] = diff } if diff := cmp.Diff(fromGraphQL.GetStart(), fromKubernetesCustomResource.Spec.QueryStart); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleField=%q", diff)) + keyValues["throttleField"] = diff } if diff := cmp.Diff(fromGraphQL.GetEnd(), fromKubernetesCustomResource.Spec.QueryEnd); diff != "" { - diffs = append(diffs, fmt.Sprintf("throttleTimeSeconds=%q", diff)) + keyValues["throttleTimeSeconds"] = diff } actionsFromGraphQL := humioapi.GetActionNames(fromGraphQL.GetActionsV2()) sort.Strings(actionsFromGraphQL) sort.Strings(fromKubernetesCustomResource.Spec.Actions) if diff := cmp.Diff(actionsFromGraphQL, fromKubernetesCustomResource.Spec.Actions); diff != "" { - diffs = append(diffs, fmt.Sprintf("actions=%q", diff)) + keyValues["actions"] = diff } if diff := cmp.Diff(fromGraphQL.GetTimeZone(), fromKubernetesCustomResource.Spec.TimeZone); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryTimestampType=%q", diff)) + keyValues["queryTimestampType"] = diff } if diff := cmp.Diff(fromGraphQL.GetQueryString(), fromKubernetesCustomResource.Spec.QueryString); diff != "" { - diffs = append(diffs, fmt.Sprintf("queryString=%q", diff)) + keyValues["queryString"] = diff } if diff := cmp.Diff(fromGraphQL.GetSchedule(), fromKubernetesCustomResource.Spec.Schedule); diff != "" { - diffs = append(diffs, fmt.Sprintf("triggerMode=%q", diff)) + keyValues["triggerMode"] = diff } if diff := cmp.Diff(fromGraphQL.GetBackfillLimit(), fromKubernetesCustomResource.Spec.BackfillLimit); diff != "" { - diffs = append(diffs, fmt.Sprintf("searchIntervalSeconds=%q", diff)) + keyValues["searchIntervalSeconds"] = diff } if diff := cmp.Diff(fromGraphQL.GetEnabled(), fromKubernetesCustomResource.Spec.Enabled); diff != "" { - diffs = append(diffs, fmt.Sprintf("enabled=%q", diff)) + keyValues["enabled"] = diff } if !humioapi.QueryOwnershipIsOrganizationOwnership(fromGraphQL.GetQueryOwnership()) { - diffs = append(diffs, fmt.Sprintf("queryOwnership=%+v", fromGraphQL.GetQueryOwnership())) + keyValues["queryOwnership"] = fmt.Sprintf("%+v", fromGraphQL.GetQueryOwnership()) } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } diff --git a/controllers/humioview_controller.go b/controllers/humioview_controller.go index 9665e423..9fde2323 100644 --- a/controllers/humioview_controller.go +++ b/controllers/humioview_controller.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "sort" - "strings" "time" "github.com/go-logr/logr" @@ -155,9 +154,9 @@ func (r *HumioViewReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return reconcile.Result{}, r.logErrorAndReturn(err, "could not check if view exists") } - if asExpected, diff := viewAlreadyAsExpected(hv, curView); !asExpected { + if asExpected, diffKeysAndValues := viewAlreadyAsExpected(hv, curView); !asExpected { r.Log.Info("information differs, triggering update", - "diff", diff, + helpers.MapToAnySlice(diffKeysAndValues)..., ) updateErr := r.HumioClient.UpdateView(ctx, humioHttpClient, req, hv) if updateErr != nil { @@ -192,25 +191,25 @@ func (r *HumioViewReconciler) logErrorAndReturn(err error, msg string) error { // viewAlreadyAsExpected compares fromKubernetesCustomResource and fromGraphQL. It returns a boolean indicating // if the details from GraphQL already matches what is in the desired state of the custom resource. -// If they do not match, a string is returned with details on what the diff is. -func viewAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioView, fromGraphQL *humiographql.GetSearchDomainSearchDomainView) (bool, string) { - var diffs []string +// If they do not match, a map is returned with details on what the diff is. +func viewAlreadyAsExpected(fromKubernetesCustomResource *humiov1alpha1.HumioView, fromGraphQL *humiographql.GetSearchDomainSearchDomainView) (bool, map[string]string) { + keyValues := map[string]string{} currentConnections := fromGraphQL.GetConnections() expectedConnections := fromKubernetesCustomResource.GetViewConnections() sortConnections(currentConnections) sortConnections(expectedConnections) if diff := cmp.Diff(currentConnections, expectedConnections); diff != "" { - diffs = append(diffs, fmt.Sprintf("viewConnections=%q", diff)) + keyValues["viewConnections"] = diff } if diff := cmp.Diff(fromGraphQL.GetDescription(), &fromKubernetesCustomResource.Spec.Description); diff != "" { - diffs = append(diffs, fmt.Sprintf("description=%q", diff)) + keyValues["description"] = diff } if diff := cmp.Diff(fromGraphQL.GetAutomaticSearch(), helpers.BoolTrue(fromKubernetesCustomResource.Spec.AutomaticSearch)); diff != "" { - diffs = append(diffs, fmt.Sprintf("automaticSearch=%q", diff)) + keyValues["automaticSearch"] = diff } - return len(diffs) == 0, strings.Join(diffs, ", ") + return len(keyValues) == 0, keyValues } func sortConnections(connections []humiographql.GetSearchDomainSearchDomainViewConnectionsViewConnection) { diff --git a/docs/api.md b/docs/api.md index 145089ec..5d9680d5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -35101,6 +35101,8 @@ This conflicts with ExternalClusterName.
integer ThrottleTimeSeconds is the throttle time in seconds. A filter alert is triggered at most once per the throttle time
+
+ Minimum: 60
false @@ -35594,6 +35596,7 @@ Retention defines the retention settings for the repository https://github.com/kubernetes-sigs/controller-tools/issues/245

Format: int32
+ Minimum: 1
false @@ -35603,6 +35606,7 @@ https://github.com/kubernetes-sigs/controller-tools/issues/245


Format: int32
+ Minimum: 1
false @@ -35612,6 +35616,7 @@ https://github.com/kubernetes-sigs/controller-tools/issues/245


Format: int32
+ Minimum: 1
false diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 3ade7ae9..e82a675c 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -184,3 +184,13 @@ func GetE2ELicenseFromEnvVar() string { func PreserveKindCluster() bool { return os.Getenv("PRESERVE_KIND_CLUSTER") == "true" } + +// MapToAnySlice converts a given map[string]string and converts it to []any. +// This is useful when e.g. passing on key-value pairs to a logger. +func MapToAnySlice(m map[string]string) []any { + result := make([]any, 0, len(m)*2) + for k, v := range m { + result = append(result, k, v) + } + return result +} From f406133bd0c398784b469263ee9088024a15ad49 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Tue, 17 Dec 2024 11:13:53 +0100 Subject: [PATCH 4/4] Remove helper image release workflow We've switched to using builds from master, tagged with the Git commit SHA of the source used to build it. --- .../release-container-helperimage.yaml | 78 ------------------- README.md | 1 - images/helper/version.go | 21 ----- 3 files changed, 100 deletions(-) delete mode 100644 .github/workflows/release-container-helperimage.yaml delete mode 100644 images/helper/version.go diff --git a/.github/workflows/release-container-helperimage.yaml b/.github/workflows/release-container-helperimage.yaml deleted file mode 100644 index 8aa3be07..00000000 --- a/.github/workflows/release-container-helperimage.yaml +++ /dev/null @@ -1,78 +0,0 @@ -on: - push: - branches: - - master - paths: - - images/helper/version.go -name: Publish Container Helper Image Release -jobs: - build-and-publish: - name: Build and Publish - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set version information - run: | - echo "RELEASE_VERSION=$(grep "Version =" images/helper/version.go | awk -F'"' '{print $2}')" >> $GITHUB_ENV - echo "RELEASE_COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_ENV - echo "RELEASE_DATE=$(date --iso-8601=seconds)" >> $GITHUB_ENV - - name: copy license to helper image dir - run: cp LICENSE images/helper/ - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build but don't push - uses: docker/build-push-action@v5 - with: - context: images/helper - # Because we use a container scanner pre-push we don't specify platform here so only the runner platform builds - # platforms: linux/amd64,linux/arm64 - load: true - tags: ${{ github.repository_owner }}/humio-operator-helper:${{ env.RELEASE_VERSION }} - labels: | - version=${{ env.RELEASE_VERSION }} - release=${{ github.run_id }} - build-args: | - RELEASE_VERSION=${{ env.RELEASE_VERSION }} - RELEASE_COMMIT=${{ env.RELEASE_COMMIT }} - RELEASE_DATE=${{ env.RELEASE_DATE }} - cache-to: type=local,type=registry,type=gha - - name: Set up Python - uses: actions/setup-python@v5 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install six - python -m pip install --upgrade retry - pip install retry - - name: CrowdStrike Container Image Scan Operator Helper - if: github.repository_owner == 'humio' - uses: crowdstrike/container-image-scan-action@v1 - with: - falcon_client_id: 1cd30708cb31442f85a6eec83279fe7b - container_repository: ${{ github.repository_owner }}/humio-operator-helper - container_tag: ${{ env.RELEASE_VERSION }} - env: - FALCON_CLIENT_SECRET: "${{ secrets.FALCON_CLIENT_SECRET }}" - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: images/helper - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ github.repository_owner }}/humio-operator-helper:${{ env.RELEASE_VERSION }} - labels: | - version=${{ env.RELEASE_VERSION }} - release=${{ github.run_id }} - build-args: | - RELEASE_VERSION=${{ env.RELEASE_VERSION }} - RELEASE_COMMIT=${{ env.RELEASE_COMMIT }} - RELEASE_DATE=${{ env.RELEASE_DATE }} - cache-from: type=gha, mode=max - cache-to: type=gha diff --git a/README.md b/README.md index 9826ab0b..5b23bc72 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ make run-e2e-tests-local-kind In order to publish new release of the different components, we have the following procedures we can follow: - Operator container image: Bump the version defined in [VERSION](VERSION). -- Helper container image: Bump the version defined in [images/helper/version.go](images/helper/version.go). - Helm chart: Bump the version defined in [charts/humio-operator/Chart.yaml](charts/humio-operator/Chart.yaml). Note: For now, we only release one component at a time due to how our workflows in GitHub Actions. diff --git a/images/helper/version.go b/images/helper/version.go deleted file mode 100644 index 8136c441..00000000 --- a/images/helper/version.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2020 Humio https://humio.com - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -var ( - Version = "0.5.0" -)