mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Fix License Timeout (#891)
This commit is contained in:
parent
9cebf15d9a
commit
df426fa2d9
8 changed files with 38 additions and 21 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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":
|
||||
|
|
Loading…
Reference in a new issue