Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update docker.io/library/golang docker tag to v1.23.1 #8018

Merged
merged 9 commits into from
Oct 1, 2024
32 changes: 17 additions & 15 deletions pkg/controller/license/trial/trial_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *ReconcileTrials) Reconcile(ctx context.Context, request reconcile.Reque

validationMsg := validateEULA(secret)
if validationMsg != "" {
return r.invalidOperation(ctx, secret, validationMsg)
return reconcile.Result{}, r.invalidOperation(ctx, secret, validationMsg)
}

// 1. reconcile trial status secret
Expand All @@ -90,23 +90,25 @@ func (r *ReconcileTrials) Reconcile(ctx context.Context, request reconcile.Reque
// 2. reconcile the trial license itself
trialLicensePopulated := license.IsMissingFields() == nil
licenseStatus := r.validateLicense(ctx, license)

switch {
case !trialLicensePopulated && r.trialState.IsTrialStarted():
// user wants to start a trial for the second time
return r.invalidOperation(ctx, secret, trialOnlyOnceMsg)
err = r.invalidOperation(ctx, secret, trialOnlyOnceMsg)
thbkrkr marked this conversation as resolved.
Show resolved Hide resolved
case !trialLicensePopulated && !r.trialState.IsTrialStarted():
// user wants to init a trial for the first time
return r.initTrialLicense(ctx, secret, license)
err = r.initTrialLicense(ctx, secret, license)
case trialLicensePopulated && !validLicense(licenseStatus):
// existing license is invalid (expired or tampered with)
return r.invalidOperation(ctx, secret, userFriendlyMsgs[licenseStatus])
err = r.invalidOperation(ctx, secret, userFriendlyMsgs[licenseStatus])
case trialLicensePopulated && validLicense(licenseStatus) && !r.trialState.IsTrialStarted():
// valid license, let's consider the trial started and complete the activation
return r.completeTrialActivation(ctx, request.NamespacedName)
err = r.completeTrialActivation(ctx, request.NamespacedName)
case trialLicensePopulated && validLicense(licenseStatus) && r.trialState.IsTrialStarted():
// all good nothing to do
}
return reconcile.Result{}, nil

return reconcile.Result{}, err
}

func (r *ReconcileTrials) reconcileTrialStatus(ctx context.Context, licenseName types.NamespacedName, license licensing.EnterpriseLicense) error {
Expand Down Expand Up @@ -175,28 +177,28 @@ func (r *ReconcileTrials) startTrialActivation() error {
return nil
}

func (r *ReconcileTrials) completeTrialActivation(ctx context.Context, license types.NamespacedName) (reconcile.Result, error) {
func (r *ReconcileTrials) completeTrialActivation(ctx context.Context, license types.NamespacedName) error {
if r.trialState.CompleteTrialActivation() {
expectedStatus, err := licensing.ExpectedTrialStatus(r.OperatorNamespace, license, r.trialState)
if err != nil {
return reconcile.Result{}, err
return err
}
_, err = reconciler.ReconcileSecret(ctx, r, expectedStatus, nil)
return reconcile.Result{}, err
return err
}
return reconcile.Result{}, nil
return nil
}

func (r *ReconcileTrials) initTrialLicense(ctx context.Context, secret corev1.Secret, license licensing.EnterpriseLicense) (reconcile.Result, error) {
func (r *ReconcileTrials) initTrialLicense(ctx context.Context, secret corev1.Secret, license licensing.EnterpriseLicense) error {
if err := r.trialState.InitTrialLicense(ctx, &license); err != nil {
return reconcile.Result{}, err
return err
}
return reconcile.Result{}, licensing.UpdateEnterpriseLicense(ctx, r, secret, license)
return licensing.UpdateEnterpriseLicense(ctx, r, secret, license)
}

func (r *ReconcileTrials) invalidOperation(ctx context.Context, secret corev1.Secret, msg string) (reconcile.Result, error) {
func (r *ReconcileTrials) invalidOperation(ctx context.Context, secret corev1.Secret, msg string) error {
setValidationMsg(ctx, &secret, msg)
return reconcile.Result{}, r.Update(ctx, &secret)
return r.Update(ctx, &secret)
}

func validLicense(status licensing.LicenseStatus) bool {
Expand Down