github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/release/pending.go (about)

     1  package release
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/invopop/jsonschema"
     7  )
     8  
     9  // PendingStrategy is a type for enumerating strategies for handling pending releases.
    10  type PendingStrategy string
    11  
    12  const (
    13  	// PendingStrategyRollback rolls back pending release.
    14  	PendingStrategyRollback PendingStrategy = "rollback"
    15  	// PendingStrategyUninstall uninstalls pending release.
    16  	PendingStrategyUninstall PendingStrategy = "uninstall"
    17  )
    18  
    19  func (PendingStrategy) JSONSchema() *jsonschema.Schema {
    20  	return &jsonschema.Schema{
    21  		Type: "string",
    22  		Enum: []any{
    23  			PendingStrategyRollback,
    24  			PendingStrategyUninstall,
    25  			"",
    26  		},
    27  	}
    28  }
    29  
    30  func (rel *config) isPending() (bool, error) {
    31  	status, err := rel.Status()
    32  	if err != nil {
    33  		return false, err
    34  	}
    35  
    36  	return status.Info.Status.IsPending(), nil
    37  }
    38  
    39  func (rel *config) fixPending(ctx context.Context) error {
    40  	switch rel.PendingReleaseStrategy {
    41  	case PendingStrategyRollback:
    42  		return rel.Rollback(ctx, 0)
    43  	case PendingStrategyUninstall:
    44  		_, err := rel.Uninstall(ctx)
    45  
    46  		return err
    47  	default:
    48  		return ErrPendingRelease
    49  	}
    50  }