diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index 803cfef23..c75500b02 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -253,7 +253,7 @@ func (d *Deployment) getConnConfig() (http.ConnectionConfig, error) { transport := &nhttp.Transport{ Proxy: nhttp.ProxyFromEnvironment, DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, + Timeout: 10 * time.Second, KeepAlive: 100 * time.Millisecond, DualStack: true, }).DialContext, diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index 90cc80811..2bcb6fce7 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -407,7 +407,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err if err := newAPIObject.Spec.Validate(); err != nil { d.CreateEvent(k8sutil.NewErrorEvent("Validation failed", err, d.apiObject)) // Try to reset object - if err := d.updateCRSpec(ctx, d.apiObject.Spec, true); err != nil { + if err := d.updateCRSpec(ctx, d.apiObject.Spec); err != nil { log.Error().Err(err).Msg("Restore original spec failed") d.CreateEvent(k8sutil.NewErrorEvent("Restore original failed", err, d.apiObject)) } @@ -421,7 +421,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err } // Save updated spec - if err := d.updateCRSpec(ctx, newAPIObject.Spec, true); err != nil { + if err := d.updateCRSpec(ctx, newAPIObject.Spec); err != nil { return errors.WithStack(errors.Newf("failed to update ArangoDeployment spec: %v", err)) } // Save updated accepted spec diff --git a/pkg/deployment/deployment_inspector.go b/pkg/deployment/deployment_inspector.go index da4366468..032fbb2ad 100644 --- a/pkg/deployment/deployment_inspector.go +++ b/pkg/deployment/deployment_inspector.go @@ -163,7 +163,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva } else { condition, exists := status.Conditions.Get(api.ConditionTypeUpToDate) if checksum != status.AppliedVersion && (!exists || condition.IsTrue()) { - if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, "Spec Changed", "Spec Object changed. Waiting until plan will be applied"); err != nil { + if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, false, "Spec Changed", "Spec Object changed. Waiting until plan will be applied", checksum); err != nil { return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition") } @@ -265,9 +265,9 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva return minInspectionInterval, errors.Wrapf(err, "Unable clean plan") } } else if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil { - d.deps.Log.Info().Msgf("Plan generated, reconciling") return minInspectionInterval, errors.Wrapf(err, "Plan creation failed") } else if updated { + d.deps.Log.Info().Msgf("Plan generated, reconciling") return minInspectionInterval, nil } @@ -284,7 +284,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva isUpToDate, reason := d.isUpToDateStatus() if !isUpToDate && status.Conditions.IsTrue(api.ConditionTypeUpToDate) { - if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, reason, "There are pending operations in plan or members are in restart process"); err != nil { + if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, false, reason, "There are pending operations in plan or members are in restart process", checksum); err != nil { return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition") } @@ -292,7 +292,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva } if isUpToDate && !status.Conditions.IsTrue(api.ConditionTypeUpToDate) { - if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, true, "Spec is Up To Date", "Spec is Up To Date"); err != nil { + if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, true, "Spec is Up To Date", "Spec is Up To Date", checksum); err != nil { return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition") } @@ -420,10 +420,10 @@ func (d *Deployment) triggerCRDInspection() { d.inspectCRDTrigger.Trigger() } -func (d *Deployment) updateCondition(ctx context.Context, conditionType api.ConditionType, status bool, reason, message string) error { - d.deps.Log.Info().Str("condition", string(conditionType)).Bool("status", status).Str("reason", reason).Str("message", message).Msg("Updated condition") +func (d *Deployment) updateConditionWithHash(ctx context.Context, conditionType api.ConditionType, status bool, reason, message, hash string) error { + d.deps.Log.Info().Str("condition", string(conditionType)).Bool("status", status).Str("reason", reason).Str("message", message).Str("hash", hash).Msg("Updated condition") if err := d.WithStatusUpdate(ctx, func(s *api.DeploymentStatus) bool { - return s.Conditions.Update(conditionType, status, reason, message) + return s.Conditions.UpdateWithHash(conditionType, status, reason, message, hash) }); err != nil { return errors.Wrapf(err, "Unable to update condition") } diff --git a/pkg/deployment/reconcile/action_set_license.go b/pkg/deployment/reconcile/action_set_license.go index 571dc1b58..74b536141 100644 --- a/pkg/deployment/reconcile/action_set_license.go +++ b/pkg/deployment/reconcile/action_set_license.go @@ -51,6 +51,9 @@ type licenseSetAction struct { } func (a *licenseSetAction) Start(ctx context.Context) (bool, error) { + ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx) + defer cancel() + log := a.log spec := a.actionCtx.GetSpec() @@ -76,9 +79,6 @@ func (a *licenseSetAction) Start(ctx context.Context) (bool, error) { return true, nil } - ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx) - defer cancel() - c, err := a.actionCtx.GetServerClient(ctxChild, group, m.ID) if !ok { log.Error().Err(err).Msg("Unable to get client") @@ -87,7 +87,7 @@ func (a *licenseSetAction) Start(ctx context.Context) (bool, error) { client := client.NewClient(c.Connection()) - if ok, err := licenseV2Compare(ctx, client, l.V2); err != nil { + if ok, err := licenseV2Compare(ctxChild, client, l.V2); err != nil { log.Error().Err(err).Msg("Unable to verify license") return true, nil } else if ok { @@ -95,7 +95,7 @@ func (a *licenseSetAction) Start(ctx context.Context) (bool, error) { return true, nil } - if err := client.SetLicense(ctx, string(l.V2), true); err != nil { + if err := client.SetLicense(ctxChild, string(l.V2), true); err != nil { log.Error().Err(err).Msg("Unable to set license") return true, nil } diff --git a/pkg/deployment/reconcile/plan_builder_generator.go b/pkg/deployment/reconcile/plan_builder_generator.go index 73171b7f6..7b9710b74 100644 --- a/pkg/deployment/reconcile/plan_builder_generator.go +++ b/pkg/deployment/reconcile/plan_builder_generator.go @@ -65,6 +65,7 @@ func (d *Reconciler) generatePlanFunc(gen planGeneratorFunc, planner planner) pl func (d *Reconciler) generatePlan(ctx context.Context, cachedStatus inspectorInterface.Inspector, generators ...planGenerator) (error, bool) { updated := false + updateRequired := false if err := d.context.WithStatusUpdate(ctx, func(s *api.DeploymentStatus) bool { var b api.BackOff @@ -103,11 +104,11 @@ func (d *Reconciler) generatePlan(ctx context.Context, cachedStatus inspectorInt if !new.Equal(s.BackOff) { s.BackOff = new - updated = true + updateRequired = true } } - return updated + return updated || updateRequired }); err != nil { return errors.WithMessage(err, "Unable to save plan"), false } diff --git a/pkg/deployment/reconcile/plan_builder_license.go b/pkg/deployment/reconcile/plan_builder_license.go index 7bf73edb4..ff5782efc 100644 --- a/pkg/deployment/reconcile/plan_builder_license.go +++ b/pkg/deployment/reconcile/plan_builder_license.go @@ -26,6 +26,7 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/client" "github.com/arangodb/kube-arangodb/pkg/util/arangod" + "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" "github.com/rs/zerolog" @@ -67,7 +68,10 @@ func updateClusterLicense(ctx context.Context, member := members[0] - c, err := context.GetServerClient(ctx, member.Group, member.Member.ID) + ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx) + defer cancel() + + c, err := context.GetServerClient(ctxChild, member.Group, member.Member.ID) if err != nil { log.Err(err).Msgf("Unable to get client") return nil @@ -75,7 +79,7 @@ func updateClusterLicense(ctx context.Context, internalClient := client.NewClient(c.Connection()) - if ok, err := licenseV2Compare(ctx, internalClient, l.V2); err != nil { + if ok, err := licenseV2Compare(ctxChild, internalClient, l.V2); err != nil { log.Error().Err(err).Msg("Unable to verify license") return nil } else if ok { diff --git a/pkg/deployment/resources/license.go b/pkg/deployment/resources/license.go index e33469fdb..916aa103f 100644 --- a/pkg/deployment/resources/license.go +++ b/pkg/deployment/resources/license.go @@ -40,9 +40,19 @@ func (r *Resources) ValidateLicenseKeySecret(cachedStatus inspectorInterface.Ins return errors.Newf("License secret %s does not exist", s) } - if _, ok := s.Data[constants.SecretKeyToken]; !ok { - return errors.Newf("Invalid secret format") + if _, ok := s.Data[constants.SecretKeyToken]; ok { + return nil } + + if _, ok := s.Data[constants.SecretKeyV2Token]; ok { + return nil + } + + if _, ok := s.Data[constants.SecretKeyV2License]; ok { + return nil + } + + return errors.Newf("Invalid secret format") } return nil diff --git a/pkg/logging/logger.go b/pkg/logging/logger.go index fad624052..65a9eb7b5 100644 --- a/pkg/logging/logger.go +++ b/pkg/logging/logger.go @@ -128,6 +128,8 @@ func (s *loggingService) MustSetLevel(name, level string) { // stringToLevel converts a level string to a zerolog level func stringToLevel(l string) (zerolog.Level, error) { switch strings.ToLower(l) { + case "trace": + return zerolog.TraceLevel, nil case "debug": return zerolog.DebugLevel, nil case "info":