...

Source file src/edge-infra.dev/pkg/edge/constants/api/fleet/fleet.go

Documentation: edge-infra.dev/pkg/edge/constants/api/fleet

     1  // Package fleet contains Edge Fleet enum constants that represent each
     2  // tier of K8s clusters in the Edge platform.
     3  package fleet
     4  
     5  import (
     6  	"fmt"
     7  
     8  	"edge-infra.dev/pkg/edge/constants"
     9  )
    10  
    11  // Label is the K8s resource label used to store fleet information.
    12  const Label = "fleet." + constants.Domain
    13  
    14  // LabelType is the type of the label in the edge database for the fleet type
    15  const LabelType = "edge-fleet"
    16  
    17  // Type is the enum type representing Edge Fleets
    18  type Type string
    19  
    20  // Fleet Types
    21  const (
    22  	TopLevel   = "top-level"
    23  	Enterprise = "enterprise"
    24  	Store      = "store"
    25  	BasicStore = "basic-store"
    26  	Banner     = "banner-infra"
    27  	Cluster    = "cluster-infra"
    28  	CouchDB    = "couchdb-masters"
    29  )
    30  
    31  func IsValid(ft string) error {
    32  	return Type(ft).IsValid()
    33  }
    34  
    35  var Types = []Type{TopLevel, Enterprise, Store, BasicStore, Banner, Cluster, CouchDB}
    36  
    37  var ErrInvalidType = fmt.Errorf("invalid fleet type, expected %v", Types)
    38  
    39  // IsValid checks that a Fleet Type enum value is correct.
    40  func (ft Type) IsValid() error {
    41  	found := false
    42  	for _, fType := range Types {
    43  		if ft == fType {
    44  			found = true
    45  		}
    46  	}
    47  	if found {
    48  		return nil
    49  	}
    50  	return fmt.Errorf("%v: %w", ft, ErrInvalidType)
    51  }
    52  
    53  // String is a convenience function for casting a fleet.Type to a string
    54  func (ft Type) String() string {
    55  	return string(ft)
    56  }
    57  
    58  type AnnotationsGetter interface {
    59  	GetAnnotations() map[string]string
    60  }
    61  
    62  func IsClusterInfraCluster(val Type) bool {
    63  	return val == Cluster
    64  }
    65  
    66  func IsStoreCluster(val Type) bool {
    67  	if val == Store {
    68  		return true
    69  	}
    70  	if val == BasicStore {
    71  		return true
    72  	}
    73  	return false
    74  }
    75  

View as plain text