Skip to content

Commit

Permalink
Define hosted providers NodePools and NodeGroups schema as a pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <[email protected]>
  • Loading branch information
valaparthvi committed Jan 28, 2025
1 parent 9350f48 commit bbac526
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type AKSClusterConfigSpec struct {
NetworkPodCIDR *string `json:"podCidr,omitempty" yaml:"podCidr,omitempty"`
NetworkPolicy *string `json:"networkPolicy,omitempty" yaml:"networkPolicy,omitempty"`
NetworkServiceCIDR *string `json:"serviceCidr,omitempty" yaml:"serviceCidr,omitempty"`
NodePools []AKSNodePool `json:"nodePools,omitempty" yaml:"nodePools,omitempty"`
NodePools *[]AKSNodePool `json:"nodePools,omitempty" yaml:"nodePools,omitempty"`
NodeResourceGroup *string `json:"nodeResourceGroup,omitempty" yaml:"nodeResourceGroup,omitempty"`
OutboundType *string `json:"outboundType,omitempty" yaml:"outboundType,omitempty"`
PrivateCluster *bool `json:"privateCluster,omitempty" yaml:"privateCluster,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ const (
ClusterRoleTemplateBindingFieldOwnerReferences = "ownerReferences"
ClusterRoleTemplateBindingFieldRemoved = "removed"
ClusterRoleTemplateBindingFieldRoleTemplateID = "roleTemplateId"
ClusterRoleTemplateBindingFieldStatus = "status"
ClusterRoleTemplateBindingFieldUUID = "uuid"
ClusterRoleTemplateBindingFieldUserID = "userId"
ClusterRoleTemplateBindingFieldUserPrincipalID = "userPrincipalId"
)

type ClusterRoleTemplateBinding struct {
types.Resource
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
ClusterID string `json:"clusterId,omitempty" yaml:"clusterId,omitempty"`
Created string `json:"created,omitempty" yaml:"created,omitempty"`
CreatorID string `json:"creatorId,omitempty" yaml:"creatorId,omitempty"`
GroupID string `json:"groupId,omitempty" yaml:"groupId,omitempty"`
GroupPrincipalID string `json:"groupPrincipalId,omitempty" yaml:"groupPrincipalId,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
NamespaceId string `json:"namespaceId,omitempty" yaml:"namespaceId,omitempty"`
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty" yaml:"ownerReferences,omitempty"`
Removed string `json:"removed,omitempty" yaml:"removed,omitempty"`
RoleTemplateID string `json:"roleTemplateId,omitempty" yaml:"roleTemplateId,omitempty"`
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
UserID string `json:"userId,omitempty" yaml:"userId,omitempty"`
UserPrincipalID string `json:"userPrincipalId,omitempty" yaml:"userPrincipalId,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
ClusterID string `json:"clusterId,omitempty" yaml:"clusterId,omitempty"`
Created string `json:"created,omitempty" yaml:"created,omitempty"`
CreatorID string `json:"creatorId,omitempty" yaml:"creatorId,omitempty"`
GroupID string `json:"groupId,omitempty" yaml:"groupId,omitempty"`
GroupPrincipalID string `json:"groupPrincipalId,omitempty" yaml:"groupPrincipalId,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
NamespaceId string `json:"namespaceId,omitempty" yaml:"namespaceId,omitempty"`
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty" yaml:"ownerReferences,omitempty"`
Removed string `json:"removed,omitempty" yaml:"removed,omitempty"`
RoleTemplateID string `json:"roleTemplateId,omitempty" yaml:"roleTemplateId,omitempty"`
Status *ClusterRoleTemplateBindingStatus `json:"status,omitempty" yaml:"status,omitempty"`
UUID string `json:"uuid,omitempty" yaml:"uuid,omitempty"`
UserID string `json:"userId,omitempty" yaml:"userId,omitempty"`
UserPrincipalID string `json:"userPrincipalId,omitempty" yaml:"userPrincipalId,omitempty"`
}

type ClusterRoleTemplateBindingCollection struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package client

const (
ClusterRoleTemplateBindingStatusType = "clusterRoleTemplateBindingStatus"
ClusterRoleTemplateBindingStatusFieldLastUpdateTime = "lastUpdateTime"
ClusterRoleTemplateBindingStatusFieldLocalConditions = "localConditions"
ClusterRoleTemplateBindingStatusFieldObservedGenerationLocal = "observedGenerationLocal"
ClusterRoleTemplateBindingStatusFieldObservedGenerationRemote = "observedGenerationRemote"
ClusterRoleTemplateBindingStatusFieldRemoteConditions = "remoteConditions"
ClusterRoleTemplateBindingStatusFieldSummary = "summary"
ClusterRoleTemplateBindingStatusFieldSummaryLocal = "summaryLocal"
ClusterRoleTemplateBindingStatusFieldSummaryRemote = "summaryRemote"
)

type ClusterRoleTemplateBindingStatus struct {
LastUpdateTime string `json:"lastUpdateTime,omitempty" yaml:"lastUpdateTime,omitempty"`
LocalConditions []Condition `json:"localConditions,omitempty" yaml:"localConditions,omitempty"`
ObservedGenerationLocal int64 `json:"observedGenerationLocal,omitempty" yaml:"observedGenerationLocal,omitempty"`
ObservedGenerationRemote int64 `json:"observedGenerationRemote,omitempty" yaml:"observedGenerationRemote,omitempty"`
RemoteConditions []Condition `json:"remoteConditions,omitempty" yaml:"remoteConditions,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
SummaryLocal string `json:"summaryLocal,omitempty" yaml:"summaryLocal,omitempty"`
SummaryRemote string `json:"summaryRemote,omitempty" yaml:"summaryRemote,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type EKSClusterConfigSpec struct {
KmsKey *string `json:"kmsKey,omitempty" yaml:"kmsKey,omitempty"`
KubernetesVersion *string `json:"kubernetesVersion,omitempty" yaml:"kubernetesVersion,omitempty"`
LoggingTypes *[]string `json:"loggingTypes,omitempty" yaml:"loggingTypes,omitempty"`
NodeGroups []NodeGroup `json:"nodeGroups,omitempty" yaml:"nodeGroups,omitempty"`
NodeGroups *[]NodeGroup `json:"nodeGroups,omitempty" yaml:"nodeGroups,omitempty"`
PrivateAccess *bool `json:"privateAccess,omitempty" yaml:"privateAccess,omitempty"`
PublicAccess *bool `json:"publicAccess,omitempty" yaml:"publicAccess,omitempty"`
PublicAccessSources *[]string `json:"publicAccessSources,omitempty" yaml:"publicAccessSources,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type GKEClusterConfigSpec struct {
MonitoringService *string `json:"monitoringService,omitempty" yaml:"monitoringService,omitempty"`
Network *string `json:"network,omitempty" yaml:"network,omitempty"`
NetworkPolicyEnabled *bool `json:"networkPolicyEnabled,omitempty" yaml:"networkPolicyEnabled,omitempty"`
NodePools []GKENodePoolConfig `json:"nodePools,omitempty" yaml:"nodePools,omitempty"`
NodePools *[]GKENodePoolConfig `json:"nodePools,omitempty" yaml:"nodePools,omitempty"`
PrivateClusterConfig *GKEPrivateClusterConfig `json:"privateClusterConfig,omitempty" yaml:"privateClusterConfig,omitempty"`
ProjectID string `json:"projectID,omitempty" yaml:"projectID,omitempty"`
Region string `json:"region,omitempty" yaml:"region,omitempty"`
Expand Down
9 changes: 6 additions & 3 deletions extensions/clusters/aks/aks_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ type NodePool struct {
VnetSubnetID *string `json:"vnetSubnetID,omitempty" yaml:"vnetSubnetID,omitempty"`
}

func aksNodePoolConstructor(aksNodePoolConfigs *[]NodePool, kubernetesVersion string) []management.AKSNodePool {
var aksNodePools []management.AKSNodePool
func aksNodePoolConstructor(aksNodePoolConfigs *[]NodePool, kubernetesVersion string) *[]management.AKSNodePool {
var aksNodePools = make([]management.AKSNodePool, 0)
if aksNodePoolConfigs == nil {
return nil
}
for _, aksNodePoolConfig := range *aksNodePoolConfigs {
aksNodePool := management.AKSNodePool{
AvailabilityZones: aksNodePoolConfig.AvailabilityZones,
Expand All @@ -90,7 +93,7 @@ func aksNodePoolConstructor(aksNodePoolConfigs *[]NodePool, kubernetesVersion st
}
aksNodePools = append(aksNodePools, aksNodePool)
}
return aksNodePools
return &aksNodePools
}

func HostClusterConfig(displayName, cloudCredentialID string, aksClusterConfig ClusterConfig) *management.AKSClusterConfigSpec {
Expand Down
18 changes: 13 additions & 5 deletions extensions/clusters/aks/nodepools.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package aks

import (
"fmt"
"time"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
"github.com/sirupsen/logrus"
kwait "k8s.io/apimachinery/pkg/util/wait"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
)

const (
Expand All @@ -21,7 +23,13 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
}

var aksConfig = clusterResp.AKSConfig
*aksConfig.NodePools[0].Count += *nodePool.NodeCount

if aksConfig.NodePools == nil {
return nil, fmt.Errorf("NodePools is empty")
}

nodePools := *aksConfig.NodePools
*nodePools[0].Count += *nodePool.NodeCount

aksHostCluster := &management.Cluster{
AKSConfig: aksConfig,
Expand All @@ -32,7 +40,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
WindowsPreferedCluster: clusterResp.WindowsPreferedCluster,
}

logrus.Infof("Scaling the agentpool to %v total nodes", *aksConfig.NodePools[0].Count)
logrus.Infof("Scaling the agentpool to %v total nodes", *nodePools[0].Count)
updatedCluster, err := client.Management.Cluster.Update(clusterResp, aksHostCluster)
if err != nil {
return nil, err
Expand All @@ -44,7 +52,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
return false, err
}

if clusterResp.State == active && clusterResp.NodeCount == *aksConfig.NodePools[0].Count {
if clusterResp.State == active && clusterResp.NodeCount == *nodePools[0].Count {
return true, nil
}

Expand Down
16 changes: 10 additions & 6 deletions extensions/clusters/bundledclusters/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/pkg/errors"

apiv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"

"github.com/rancher/shepherd/clients/rancher"
v3 "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
v1 "github.com/rancher/shepherd/clients/rancher/v1"
Expand Down Expand Up @@ -178,26 +179,29 @@ func (bc *BundledCluster) UpdateNodepoolKubernetesVersions(client *rancher.Clien

switch bc.Meta.Provider {
case clusters.KubernetesProviderGKE:
for i := range cluster.V3.GKEConfig.NodePools {
cluster.V3.GKEConfig.NodePools[i].Version = versionToUpgrade
configNodePools := *cluster.V3.GKEConfig.NodePools
for i := range configNodePools {
configNodePools[i].Version = versionToUpgrade
}

updatedCluster, err = bc.Update(client, cluster)
if err != nil {
return
}
case clusters.KubernetesProviderAKS:
for i := range cluster.V3.AKSConfig.NodePools {
cluster.V3.AKSConfig.NodePools[i].OrchestratorVersion = versionToUpgrade
configNodePools := *cluster.V3.AKSConfig.NodePools
for i := range configNodePools {
configNodePools[i].OrchestratorVersion = versionToUpgrade
}

updatedCluster, err = bc.Update(client, cluster)
if err != nil {
return
}
case clusters.KubernetesProviderEKS:
for i := range cluster.V3.EKSConfig.NodeGroups {
cluster.V3.EKSConfig.NodeGroups[i].Version = versionToUpgrade
configNodeGroups := *cluster.V3.EKSConfig.NodeGroups
for i := range configNodeGroups {
configNodeGroups[i].Version = versionToUpgrade
}

updatedCluster, err = bc.Update(client, cluster)
Expand Down
9 changes: 6 additions & 3 deletions extensions/clusters/eks/eks_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ type LaunchTemplateConfig struct {
Version *int64 `json:"version,omitempty" yaml:"version,omitempty"`
}

func nodeGroupsConstructor(nodeGroupsConfig *[]NodeGroupConfig, kubernetesVersion string) []management.NodeGroup {
var nodeGroups []management.NodeGroup
func nodeGroupsConstructor(nodeGroupsConfig *[]NodeGroupConfig, kubernetesVersion string) *[]management.NodeGroup {
var nodeGroups = make([]management.NodeGroup, 0)
if nodeGroupsConfig == nil {
return nil
}
for _, nodeGroupConfig := range *nodeGroupsConfig {
var launchTemplate *management.LaunchTemplate
if nodeGroupConfig.LaunchTemplateConfig != nil {
Expand Down Expand Up @@ -99,7 +102,7 @@ func nodeGroupsConstructor(nodeGroupsConfig *[]NodeGroupConfig, kubernetesVersio
}
nodeGroups = append(nodeGroups, nodeGroup)
}
return nodeGroups
return &nodeGroups
}

func eksHostClusterConfig(displayName, cloudCredentialID string, eksClusterConfig ClusterConfig) *management.EKSClusterConfigSpec {
Expand Down
17 changes: 12 additions & 5 deletions extensions/clusters/eks/nodepools.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package eks

import (
"fmt"
"time"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
"github.com/sirupsen/logrus"
kwait "k8s.io/apimachinery/pkg/util/wait"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
)

const (
Expand All @@ -21,7 +23,12 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
}

var eksConfig = clusterResp.EKSConfig
*eksConfig.NodeGroups[0].DesiredSize += *nodePool.DesiredSize
if eksConfig.NodeGroups == nil {
return nil, fmt.Errorf("NodeGroups is empty")
}

nodeGroups := *eksConfig.NodeGroups
*nodeGroups[0].DesiredSize += *nodePool.DesiredSize

eksHostCluster := &management.Cluster{
DockerRootDir: "/var/lib/docker",
Expand All @@ -32,7 +39,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
WindowsPreferedCluster: clusterResp.WindowsPreferedCluster,
}

logrus.Infof("Scaling the node group to %v total nodes", *eksConfig.NodeGroups[0].DesiredSize)
logrus.Infof("Scaling the node group to %v total nodes", *nodeGroups[0].DesiredSize)
updatedCluster, err := client.Management.Cluster.Update(clusterResp, eksHostCluster)
if err != nil {
return nil, err
Expand All @@ -44,7 +51,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
return false, err
}

if clusterResp.State == active && clusterResp.NodeCount == *eksConfig.NodeGroups[0].DesiredSize {
if clusterResp.State == active && clusterResp.NodeCount == *nodeGroups[0].DesiredSize {
return true, nil
}

Expand Down
9 changes: 6 additions & 3 deletions extensions/clusters/gke/gke_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ func cidrBlocksBuilder(cidrBlocks []CidrBlock) []management.GKECidrBlock {
return newCidrBlocks
}

func nodePoolsBuilder(nodePools []NodePool, kubernetesVersion *string) []management.GKENodePoolConfig {
var gkeNodePoolConfigs []management.GKENodePoolConfig
func nodePoolsBuilder(nodePools []NodePool, kubernetesVersion *string) *[]management.GKENodePoolConfig {
var gkeNodePoolConfigs = make([]management.GKENodePoolConfig, 0)
if nodePools == nil {
return nil
}
for _, nodePool := range nodePools {
gkeNodePoolConfig := management.GKENodePoolConfig{
Autoscaling: autoScallingBuilder(nodePool.Autoscaling),
Expand All @@ -203,7 +206,7 @@ func nodePoolsBuilder(nodePools []NodePool, kubernetesVersion *string) []managem

gkeNodePoolConfigs = append(gkeNodePoolConfigs, gkeNodePoolConfig)
}
return gkeNodePoolConfigs
return &gkeNodePoolConfigs
}

func nodePoolManagementBuilder(nodePoolManagement *NodePoolManagement) *management.GKENodePoolManagement {
Expand Down
17 changes: 12 additions & 5 deletions extensions/clusters/gke/nodepools.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package gke

import (
"fmt"
"time"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
"github.com/sirupsen/logrus"
kwait "k8s.io/apimachinery/pkg/util/wait"

"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
)

const (
Expand All @@ -21,7 +23,12 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
}

var gkeConfig = clusterResp.GKEConfig
*gkeConfig.NodePools[0].InitialNodeCount += *nodePool.InitialNodeCount
if gkeConfig.NodePools == nil {
return nil, fmt.Errorf("NodePools is empty")
}

nodePools := *gkeConfig.NodePools
*nodePools[0].InitialNodeCount += *nodePool.InitialNodeCount

gkeHostCluster := &management.Cluster{
DockerRootDir: "/var/lib/docker",
Expand All @@ -32,7 +39,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
WindowsPreferedCluster: clusterResp.WindowsPreferedCluster,
}

logrus.Infof("Scaling the node pool to %v total nodes", *gkeConfig.NodePools[0].InitialNodeCount)
logrus.Infof("Scaling the node pool to %v total nodes", *nodePools[0].InitialNodeCount)
updatedCluster, err := client.Management.Cluster.Update(clusterResp, gkeHostCluster)
if err != nil {
return nil, err
Expand All @@ -44,7 +51,7 @@ func updateNodePoolQuantity(client *rancher.Client, cluster *management.Cluster,
return false, err
}

if clusterResp.State == active && clusterResp.NodeCount == *gkeConfig.NodePools[0].InitialNodeCount {
if clusterResp.State == active && clusterResp.NodeCount == *nodePools[0].InitialNodeCount {
return true, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.5
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.0
github.com/rancher/aks-operator v1.10.0
github.com/rancher/apiserver v0.0.0-20240604183424-8c448886365e
github.com/rancher/eks-operator v1.10.0
github.com/rancher/fleet/pkg/apis v0.11.0
Expand Down Expand Up @@ -134,7 +135,6 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rancher/aks-operator v1.10.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
Loading

0 comments on commit bbac526

Please sign in to comment.