Skip to content

Commit df426fa

Browse files
authored
[Bugfix] Fix License Timeout (#891)
1 parent 9cebf15 commit df426fa

File tree

8 files changed

+38
-21
lines changed

8 files changed

+38
-21
lines changed

pkg/deployment/context_impl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (d *Deployment) getConnConfig() (http.ConnectionConfig, error) {
253253
transport := &nhttp.Transport{
254254
Proxy: nhttp.ProxyFromEnvironment,
255255
DialContext: (&net.Dialer{
256-
Timeout: 30 * time.Second,
256+
Timeout: 10 * time.Second,
257257
KeepAlive: 100 * time.Millisecond,
258258
DualStack: true,
259259
}).DialContext,

pkg/deployment/deployment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err
407407
if err := newAPIObject.Spec.Validate(); err != nil {
408408
d.CreateEvent(k8sutil.NewErrorEvent("Validation failed", err, d.apiObject))
409409
// Try to reset object
410-
if err := d.updateCRSpec(ctx, d.apiObject.Spec, true); err != nil {
410+
if err := d.updateCRSpec(ctx, d.apiObject.Spec); err != nil {
411411
log.Error().Err(err).Msg("Restore original spec failed")
412412
d.CreateEvent(k8sutil.NewErrorEvent("Restore original failed", err, d.apiObject))
413413
}
@@ -421,7 +421,7 @@ func (d *Deployment) handleArangoDeploymentUpdatedEvent(ctx context.Context) err
421421
}
422422

423423
// Save updated spec
424-
if err := d.updateCRSpec(ctx, newAPIObject.Spec, true); err != nil {
424+
if err := d.updateCRSpec(ctx, newAPIObject.Spec); err != nil {
425425
return errors.WithStack(errors.Newf("failed to update ArangoDeployment spec: %v", err))
426426
}
427427
// Save updated accepted spec

pkg/deployment/deployment_inspector.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
163163
} else {
164164
condition, exists := status.Conditions.Get(api.ConditionTypeUpToDate)
165165
if checksum != status.AppliedVersion && (!exists || condition.IsTrue()) {
166-
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, "Spec Changed", "Spec Object changed. Waiting until plan will be applied"); err != nil {
166+
if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, false, "Spec Changed", "Spec Object changed. Waiting until plan will be applied", checksum); err != nil {
167167
return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition")
168168
}
169169

@@ -265,9 +265,9 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
265265
return minInspectionInterval, errors.Wrapf(err, "Unable clean plan")
266266
}
267267
} else if err, updated := d.reconciler.CreatePlan(ctx, cachedStatus); err != nil {
268-
d.deps.Log.Info().Msgf("Plan generated, reconciling")
269268
return minInspectionInterval, errors.Wrapf(err, "Plan creation failed")
270269
} else if updated {
270+
d.deps.Log.Info().Msgf("Plan generated, reconciling")
271271
return minInspectionInterval, nil
272272
}
273273

@@ -284,15 +284,15 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
284284
isUpToDate, reason := d.isUpToDateStatus()
285285

286286
if !isUpToDate && status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
287-
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, false, reason, "There are pending operations in plan or members are in restart process"); err != nil {
287+
if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, false, reason, "There are pending operations in plan or members are in restart process", checksum); err != nil {
288288
return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition")
289289
}
290290

291291
return minInspectionInterval, nil
292292
}
293293

294294
if isUpToDate && !status.Conditions.IsTrue(api.ConditionTypeUpToDate) {
295-
if err = d.updateCondition(ctx, api.ConditionTypeUpToDate, true, "Spec is Up To Date", "Spec is Up To Date"); err != nil {
295+
if err = d.updateConditionWithHash(ctx, api.ConditionTypeUpToDate, true, "Spec is Up To Date", "Spec is Up To Date", checksum); err != nil {
296296
return minInspectionInterval, errors.Wrapf(err, "Unable to update UpToDate condition")
297297
}
298298

@@ -420,10 +420,10 @@ func (d *Deployment) triggerCRDInspection() {
420420
d.inspectCRDTrigger.Trigger()
421421
}
422422

423-
func (d *Deployment) updateCondition(ctx context.Context, conditionType api.ConditionType, status bool, reason, message string) error {
424-
d.deps.Log.Info().Str("condition", string(conditionType)).Bool("status", status).Str("reason", reason).Str("message", message).Msg("Updated condition")
423+
func (d *Deployment) updateConditionWithHash(ctx context.Context, conditionType api.ConditionType, status bool, reason, message, hash string) error {
424+
d.deps.Log.Info().Str("condition", string(conditionType)).Bool("status", status).Str("reason", reason).Str("message", message).Str("hash", hash).Msg("Updated condition")
425425
if err := d.WithStatusUpdate(ctx, func(s *api.DeploymentStatus) bool {
426-
return s.Conditions.Update(conditionType, status, reason, message)
426+
return s.Conditions.UpdateWithHash(conditionType, status, reason, message, hash)
427427
}); err != nil {
428428
return errors.Wrapf(err, "Unable to update condition")
429429
}

pkg/deployment/reconcile/action_set_license.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type licenseSetAction struct {
5151
}
5252

5353
func (a *licenseSetAction) Start(ctx context.Context) (bool, error) {
54+
ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx)
55+
defer cancel()
56+
5457
log := a.log
5558

5659
spec := a.actionCtx.GetSpec()
@@ -76,9 +79,6 @@ func (a *licenseSetAction) Start(ctx context.Context) (bool, error) {
7679
return true, nil
7780
}
7881

79-
ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx)
80-
defer cancel()
81-
8282
c, err := a.actionCtx.GetServerClient(ctxChild, group, m.ID)
8383
if !ok {
8484
log.Error().Err(err).Msg("Unable to get client")
@@ -87,15 +87,15 @@ func (a *licenseSetAction) Start(ctx context.Context) (bool, error) {
8787

8888
client := client.NewClient(c.Connection())
8989

90-
if ok, err := licenseV2Compare(ctx, client, l.V2); err != nil {
90+
if ok, err := licenseV2Compare(ctxChild, client, l.V2); err != nil {
9191
log.Error().Err(err).Msg("Unable to verify license")
9292
return true, nil
9393
} else if ok {
9494
// Already latest license
9595
return true, nil
9696
}
9797

98-
if err := client.SetLicense(ctx, string(l.V2), true); err != nil {
98+
if err := client.SetLicense(ctxChild, string(l.V2), true); err != nil {
9999
log.Error().Err(err).Msg("Unable to set license")
100100
return true, nil
101101
}

pkg/deployment/reconcile/plan_builder_generator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (d *Reconciler) generatePlanFunc(gen planGeneratorFunc, planner planner) pl
6565

6666
func (d *Reconciler) generatePlan(ctx context.Context, cachedStatus inspectorInterface.Inspector, generators ...planGenerator) (error, bool) {
6767
updated := false
68+
updateRequired := false
6869

6970
if err := d.context.WithStatusUpdate(ctx, func(s *api.DeploymentStatus) bool {
7071
var b api.BackOff
@@ -103,11 +104,11 @@ func (d *Reconciler) generatePlan(ctx context.Context, cachedStatus inspectorInt
103104

104105
if !new.Equal(s.BackOff) {
105106
s.BackOff = new
106-
updated = true
107+
updateRequired = true
107108
}
108109
}
109110

110-
return updated
111+
return updated || updateRequired
111112
}); err != nil {
112113
return errors.WithMessage(err, "Unable to save plan"), false
113114
}

pkg/deployment/reconcile/plan_builder_license.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2727
"github.com/arangodb/kube-arangodb/pkg/deployment/client"
2828
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
29+
"github.com/arangodb/kube-arangodb/pkg/util/globals"
2930
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3031
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
3132
"github.com/rs/zerolog"
@@ -67,15 +68,18 @@ func updateClusterLicense(ctx context.Context,
6768

6869
member := members[0]
6970

70-
c, err := context.GetServerClient(ctx, member.Group, member.Member.ID)
71+
ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx)
72+
defer cancel()
73+
74+
c, err := context.GetServerClient(ctxChild, member.Group, member.Member.ID)
7175
if err != nil {
7276
log.Err(err).Msgf("Unable to get client")
7377
return nil
7478
}
7579

7680
internalClient := client.NewClient(c.Connection())
7781

78-
if ok, err := licenseV2Compare(ctx, internalClient, l.V2); err != nil {
82+
if ok, err := licenseV2Compare(ctxChild, internalClient, l.V2); err != nil {
7983
log.Error().Err(err).Msg("Unable to verify license")
8084
return nil
8185
} else if ok {

pkg/deployment/resources/license.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,19 @@ func (r *Resources) ValidateLicenseKeySecret(cachedStatus inspectorInterface.Ins
4040
return errors.Newf("License secret %s does not exist", s)
4141
}
4242

43-
if _, ok := s.Data[constants.SecretKeyToken]; !ok {
44-
return errors.Newf("Invalid secret format")
43+
if _, ok := s.Data[constants.SecretKeyToken]; ok {
44+
return nil
4545
}
46+
47+
if _, ok := s.Data[constants.SecretKeyV2Token]; ok {
48+
return nil
49+
}
50+
51+
if _, ok := s.Data[constants.SecretKeyV2License]; ok {
52+
return nil
53+
}
54+
55+
return errors.Newf("Invalid secret format")
4656
}
4757

4858
return nil

pkg/logging/logger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ func (s *loggingService) MustSetLevel(name, level string) {
128128
// stringToLevel converts a level string to a zerolog level
129129
func stringToLevel(l string) (zerolog.Level, error) {
130130
switch strings.ToLower(l) {
131+
case "trace":
132+
return zerolog.TraceLevel, nil
131133
case "debug":
132134
return zerolog.DebugLevel, nil
133135
case "info":

0 commit comments

Comments
 (0)