...
1 package v1alpha1
2
3 import (
4 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5
6 "edge-infra.dev/pkg/edge/api/graph/model"
7 clusterConstant "edge-infra.dev/pkg/edge/constants/api/cluster"
8 "edge-infra.dev/pkg/edge/constants/api/fleet"
9 )
10
11 const (
12
13 ClusterKind = "Cluster"
14
15 ClusterNS = "clusters"
16 )
17
18 func OwnerReference(cluster *Cluster) []v1.OwnerReference {
19 return []v1.OwnerReference{
20 *v1.NewControllerRef(cluster, GroupVersion.WithKind(ClusterGVK.Kind)),
21 }
22 }
23
24
25 func NewCluster(name, projectID, organization, _fleet, _type, location, nodeVersion, machineType, clusterEdgeID string, numNodes int, banner *model.Banner) *Cluster {
26 clusterName := clusterEdgeID
27 return &Cluster{
28 TypeMeta: v1.TypeMeta{
29 Kind: ClusterKind,
30 APIVersion: GroupVersion.String(),
31 },
32 ObjectMeta: v1.ObjectMeta{
33 Name: clusterName,
34 },
35 Spec: ClusterSpec{
36 Name: name,
37 ProjectID: projectID,
38 Banner: banner.Name,
39 BannerEdgeID: banner.BannerEdgeID,
40 Organization: organization,
41 Fleet: fleet.Type(_fleet),
42 Type: clusterConstant.Type(_type),
43 Location: location,
44 NodeVersion: nodeVersion,
45 NumNode: numNodes,
46 MachineType: machineType,
47 },
48 }
49 }
50
51 func (c *Cluster) AddAutoscaling(autoscale bool, minNodes, maxNodes int) {
52 c.Spec.Autoscale = autoscale
53 c.Spec.MaxNodes = maxNodes
54 c.Spec.MinNodes = minNodes
55 }
56
View as plain text