Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/deployment/context_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/deployment/deployment_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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
}

Expand All @@ -284,15 +284,15 @@ 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")
}

return minInspectionInterval, nil
}

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")
}

Expand Down Expand Up @@ -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")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/deployment/reconcile/action_set_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -87,15 +87,15 @@ 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 {
// Already latest license
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
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/deployment/reconcile/plan_builder_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/deployment/reconcile/plan_builder_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -67,15 +68,18 @@ 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
}

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 {
Expand Down
14 changes: 12 additions & 2 deletions pkg/deployment/resources/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down