Skip to content

Commit

Permalink
Add enum methods for ClusterManager
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Feb 25, 2024
1 parent 994795c commit e0c1952
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
17 changes: 15 additions & 2 deletions api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,28 @@ type ClusterMetadata struct {
Provider HostingProvider `json:"provider,omitempty" protobuf:"bytes,4,opt,name=provider,casttype=HostingProvider"`
}

/*
ENUM(
ACE = 1
OCMHub = 2
OCMMulticlusterControlplane = 4
OCMSpoke = 8
OpenShift = 16
Rancher = 32
VirtualCluster = 64
)
*/
type ClusterManager int

const (
ClusterManagerACE ClusterManager = 1 << iota
ClusterManagerOCMHub
ClusterManagerOCMSpoke
ClusterManagerOCMMulticlusterControlplane
ClusterManagerRancher
ClusterManagerOCMSpoke
ClusterManagerOpenShift
ClusterManagerRancher
ClusterManagerVirtualCluster
)

Expand Down
84 changes: 84 additions & 0 deletions api/v1/cluster_enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"fmt"
"strings"
)

var ErrInvalidClusterManager = fmt.Errorf("not a valid ClusterManager, try [%s]", strings.Join(_ClusterManagerNames, ", "))

const _ClusterManagerName = "ACEOCMHubOCMMulticlusterControlplaneOCMSpokeOpenShiftRancherVirtualCluster"

var _ClusterManagerNames = []string{
_ClusterManagerName[0:3],
_ClusterManagerName[3:9],
_ClusterManagerName[9:36],
_ClusterManagerName[36:44],
_ClusterManagerName[44:53],
_ClusterManagerName[53:60],
_ClusterManagerName[60:74],
}

// ClusterManagerNames returns a list of possible string values of ClusterManager.
func ClusterManagerNames() []string {
tmp := make([]string, len(_ClusterManagerNames))
copy(tmp, _ClusterManagerNames)
return tmp
}

// ClusterManagerValues returns a list of the values for ClusterManager
func ClusterManagerValues() []ClusterManager {
return []ClusterManager{
ClusterManagerACE,
ClusterManagerOCMHub,
ClusterManagerOCMMulticlusterControlplane,
ClusterManagerOCMSpoke,
ClusterManagerOpenShift,
ClusterManagerRancher,
ClusterManagerVirtualCluster,
}
}

var _ClusterManagerMap = map[ClusterManager]string{

Check failure on line 58 in api/v1/cluster_enum.go

View workflow job for this annotation

GitHub Actions / Build

var `_ClusterManagerMap` is unused (unused)
ClusterManagerACE: _ClusterManagerName[0:3],
ClusterManagerOCMHub: _ClusterManagerName[3:9],
ClusterManagerOCMMulticlusterControlplane: _ClusterManagerName[9:36],
ClusterManagerOCMSpoke: _ClusterManagerName[36:44],
ClusterManagerOpenShift: _ClusterManagerName[44:53],
ClusterManagerRancher: _ClusterManagerName[53:60],
ClusterManagerVirtualCluster: _ClusterManagerName[60:74],
}

var _ClusterManagerValue = map[string]ClusterManager{
_ClusterManagerName[0:3]: ClusterManagerACE,
_ClusterManagerName[3:9]: ClusterManagerOCMHub,
_ClusterManagerName[9:36]: ClusterManagerOCMMulticlusterControlplane,
_ClusterManagerName[36:44]: ClusterManagerOCMSpoke,
_ClusterManagerName[44:53]: ClusterManagerOpenShift,
_ClusterManagerName[53:60]: ClusterManagerRancher,
_ClusterManagerName[60:74]: ClusterManagerVirtualCluster,
}

// ParseClusterManager attempts to convert a string to a ClusterManager.
func ParseClusterManager(name string) (ClusterManager, error) {
if x, ok := _ClusterManagerValue[name]; ok {
return x, nil
}
return ClusterManager(0), fmt.Errorf("%s is %w", name, ErrInvalidClusterManager)
}

0 comments on commit e0c1952

Please sign in to comment.