// Package cluster contains Edge Cluster enum constants. package cluster import ( "flag" "fmt" "edge-infra.dev/pkg/edge/api/graph/model" ) const ( GKE = "gke" Generic = "generic" DSDS = "dsds" Label = "cluster.edge.ncr.com/type" ) // LabelType is the type of the label in the edge database for the cluster type const LabelType = "edge-type" // Type is the enum type representing Edge Cluster Types type Type string var Types = []Type{GKE, Generic, DSDS} // String is a convenience function for casting a cluster.Type to a string func (t Type) String() string { return string(t) } // StrArray converts an array of cluster.Type into strings func StrArray(tt []Type) (s []string) { for _, t := range tt { s = append(s, t.String()) } return } // TenantClusterTypeNameFormat is the name format for ClusterSelector tenant cluster types const TenantClusterTypeNameFormat = "tenant-%s-cluster-type-%s" var ErrInvalidType = fmt.Errorf("invalid cluster type, expected one of %s", Types) // IsValid checks that a Cluster Type enum value is correct. func (t Type) IsValid() error { found := false for _, ct := range Types { if t == ct { found = true } } if found { return nil } return fmt.Errorf("%v: %w", t, ErrInvalidType) } func (t Type) IsGKE() bool { return string(t) == GKE } func (t Type) IsDSDS() bool { return string(t) == DSDS } // RegisterTypeFlag registers a flag for specifying the cluster type at the command // line, binding the value to the provided destination pointer. func RegisterTypeFlag(fs *flag.FlagSet, dest *string) { fs.StringVar(dest, "cluster-type", Generic, fmt.Sprintf("what type of cluster, must be one of: %s", Types)) } func GetClusterTypeFromLabels(labels []*model.Label) Type { for _, l := range labels { t := Type(l.Key) if err := t.IsValid(); err == nil && l.Type == "edge" { return t } } return "" }