@@ -14,15 +14,14 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ //go:generate go-enum --mustparse --names --values
1718package v1
1819
1920import (
2021 "crypto/hmac"
2122 "crypto/sha256"
2223 "encoding/base64"
2324 "fmt"
24- "math/bits"
25- "strings"
2625)
2726
2827// +kubebuilder:validation:Enum=AKS;DigitalOcean;EKS;Exoscale;Generic;GKE;Linode;Packet;Rancher;Scaleway;Vultr
@@ -58,6 +57,7 @@ const (
5857 ClusterNameKey string = "cluster.appscode.com/name"
5958 ClusterDisplayNameKey string = "cluster.appscode.com/display-name"
6059 ClusterProviderNameKey string = "cluster.appscode.com/provider"
60+ ClusterModeKey string = "cluster.appscode.com/mode"
6161 ClusterProfileLabel string = "cluster.appscode.com/profile"
6262
6363 AceOrgIDKey string = "ace.appscode.com/org-id"
@@ -83,6 +83,7 @@ type ClusterMetadata struct {
8383 ManagerID string `json:"managerID,omitempty" protobuf:"bytes,9,opt,name=managerID"`
8484 HubClusterID string `json:"hubClusterID,omitempty" protobuf:"bytes,10,opt,name=hubClusterID"`
8585 CloudServiceAuthMode string `json:"cloudServiceAuthMode,omitempty" protobuf:"bytes,11,opt,name=cloudServiceAuthMode"`
86+ Mode ClusterMode `json:"mode,omitempty" protobuf:"bytes,12,opt,name=mode,casttype=ClusterMode"`
8687}
8788
8889func (md ClusterMetadata ) Manager () string {
@@ -99,100 +100,17 @@ func (md ClusterMetadata) State() string {
99100 return base64 .URLEncoding .EncodeToString (hasher .Sum (nil ))
100101}
101102
102- /*
103- ENUM(
104-
105- ACE = 1
106- OCMHub = 2
107- OCMMulticlusterControlplane = 4
108- OCMSpoke = 8
109- OpenShift = 16
110- Rancher = 32
111- VirtualCluster = 64
112-
113- )
114- */
115- type ClusterManager int
116-
117- const (
118- ClusterManagerACE ClusterManager = 1 << iota
119- ClusterManagerOCMHub
120- ClusterManagerOCMMulticlusterControlplane
121- ClusterManagerOCMSpoke
122- ClusterManagerOpenShift
123- ClusterManagerRancher
124- ClusterManagerVirtualCluster
125- )
126-
127- func (cm ClusterManager ) ManagedByACE () bool {
128- return cm & ClusterManagerACE == ClusterManagerACE
129- }
103+ // +kubebuilder:validation:Enum=prod;qa;staging;dev
104+ // ENUM(prod,qa,staging,dev)
105+ type ClusterMode string
130106
131- func (cm ClusterManager ) ManagedByOCMHub () bool {
132- return cm & ClusterManagerOCMHub == ClusterManagerOCMHub
133- }
134-
135- func (cm ClusterManager ) ManagedByOCMSpoke () bool {
136- return cm & ClusterManagerOCMSpoke == ClusterManagerOCMSpoke
137- }
138-
139- func (cm ClusterManager ) ManagedByOCMMulticlusterControlplane () bool {
140- return cm & ClusterManagerOCMMulticlusterControlplane == ClusterManagerOCMMulticlusterControlplane
141- }
142-
143- func (cm ClusterManager ) ManagedByRancher () bool {
144- return cm & ClusterManagerRancher == ClusterManagerRancher
145- }
146-
147- func (cm ClusterManager ) ManagedByOpenShift () bool {
148- return cm & ClusterManagerOpenShift == ClusterManagerOpenShift
149- }
150-
151- func (cm ClusterManager ) ManagedByVirtualCluster () bool {
152- return cm & ClusterManagerVirtualCluster == ClusterManagerVirtualCluster
153- }
154-
155- func (cm ClusterManager ) Strings () []string {
156- out := make ([]string , 0 , 7 )
157- if cm .ManagedByACE () {
158- out = append (out , "ACE" )
159- }
160- if cm .ManagedByOCMHub () {
161- out = append (out , "OCMHub" )
162- }
163- if cm .ManagedByOCMSpoke () {
164- out = append (out , "OCMSpoke" )
165- }
166- if cm .ManagedByOCMMulticlusterControlplane () {
167- out = append (out , "OCMMulticlusterControlplane" )
168- }
169- if cm .ManagedByRancher () {
170- out = append (out , "Rancher" )
171- }
172- if cm .ManagedByOpenShift () {
173- out = append (out , "OpenShift" )
174- }
175- if cm .ManagedByVirtualCluster () {
176- out = append (out , "vcluster" )
177- }
178- return out
179- }
180-
181- func isPowerOfTwo (n int ) bool {
182- return n > 0 && (n & (n - 1 )) == 0
183- }
184-
185- func (cm ClusterManager ) Name () string {
186- if ! isPowerOfTwo (int (cm )) {
187- return cm .String ()
188- }
189- idx := bits .TrailingZeros (uint (cm ))
190- return _ClusterManagerNames [idx ]
191- }
192-
193- func (cm ClusterManager ) String () string {
194- return strings .Join (cm .Strings (), "," )
195- }
107+ //
108+ //const (
109+ // ClusterModeProd ClusterMode = "prod"
110+ // ClusterModeQA ClusterMode = "qa"
111+ // ClusterModeStaging ClusterMode = "staging"
112+ // ClusterModeDev ClusterMode = "dev"
113+ //)
196114
197115type CAPIClusterInfo struct {
198116 Provider CAPIProvider `json:"provider" protobuf:"bytes,1,opt,name=provider,casttype=CAPIProvider"`
@@ -221,11 +139,11 @@ const (
221139)
222140
223141type ClusterClaimInfo struct {
224- ClusterMetadata ClusterInfo `json:"clusterMetadata"`
142+ ClusterMetadata ClusterInfo `json:"clusterMetadata" protobuf:"bytes,1,opt,name=clusterMetadata" `
225143}
226144
227145type ClusterClaimFeatures struct {
228- EnabledFeatures []string `json:"enabledFeatures,omitempty"`
229- ExternallyManagedFeatures []string `json:"externallyManagedFeatures,omitempty"`
230- DisabledFeatures []string `json:"disabledFeatures,omitempty"`
146+ EnabledFeatures []string `json:"enabledFeatures,omitempty" protobuf:"bytes,1,rep,name=enabledFeatures" `
147+ ExternallyManagedFeatures []string `json:"externallyManagedFeatures,omitempty" protobuf:"bytes,2,rep,name=externallyManagedFeatures" `
148+ DisabledFeatures []string `json:"disabledFeatures,omitempty" protobuf:"bytes,3,rep,name=disabledFeatures" `
231149}
0 commit comments