Skip to content

Commit

Permalink
MKAAS-1283 Add support for advanced k8s settings (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbernady authored Jun 24, 2024
1 parent c307510 commit fe85a2a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 14 deletions.
79 changes: 66 additions & 13 deletions gcore/k8s/v2/clusters/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,31 @@ type CreateOptsBuilder interface {
ToClusterCreateMap() (map[string]interface{}, error)
}

type AuthenticationCreateOpts struct {
OIDC *OIDCCreateOpts `json:"oidc,omitempty" validate:"omitempty"`
}

type OIDCCreateOpts struct {
ClientID string `json:"client_id,omitempty" validate:"omitempty"`
GroupsClaim string `json:"groups_claim,omitempty" validate:"omitempty"`
GroupsPrefix string `json:"groups_prefix,omitempty" validate:"omitempty"`
IssuerURL string `json:"issuer_url,omitempty" validate:"omitempty"`
RequiredClaims map[string]string `json:"required_claims,omitempty" validate:"omitempty"`
SigningAlgs []string `json:"signing_algs,omitempty" validate:"omitempty"`
UsernameClaim string `json:"username_claim,omitempty" validate:"omitempty"`
UsernamePrefix string `json:"username_prefix,omitempty" validate:"omitempty"`
}

type CiliumCreateOpts struct {
MaskSize int `json:"mask_size,omitempty"`
MaskSizeV6 int `json:"mask_size_v6,omitempty"`
Tunnel TunnelType `json:"tunnel,omitempty"`
Encryption bool `json:"encryption"`
LoadBalancerMode LBModeType `json:"lb_mode,omitemtpy"`
LoadBalancerMode LBModeType `json:"lb_mode,omitempty"`
LoadBalancerAcceleration bool `json:"lb_acceleration"`
RoutingMode RoutingModeType `json:"routing_mode,omitempty"`
HubbleRelay bool `json:"hubble_relay"`
HubbleUI bool `json:"hubble_ui"`
}

type CNICreateOpts struct {
Expand All @@ -62,18 +79,20 @@ type CNICreateOpts struct {

// CreateOpts represents options used to create a cluster.
type CreateOpts struct {
Name string `json:"name" required:"true" validate:"required,gt=0,lte=20"`
CNI *CNICreateOpts `json:"cni,omitempty" validate:"omitempty"`
FixedNetwork string `json:"fixed_network" validate:"omitempty,uuid4"`
FixedSubnet string `json:"fixed_subnet" validate:"omitempty,uuid4"`
PodsIPPool *gcorecloud.CIDR `json:"pods_ip_pool,omitempty" validate:"omitempty,cidr"`
ServicesIPPool *gcorecloud.CIDR `json:"services_ip_pool,omitempty" validate:"omitempty,cidr"`
PodsIPV6Pool *gcorecloud.CIDR `json:"pods_ipv6_pool,omitempty" validate:"omitempty,cidr"`
ServicesIPV6Pool *gcorecloud.CIDR `json:"services_ipv6_pool,omitempty" validate:"omitempty,cidr"`
KeyPair string `json:"keypair" required:"true" validate:"required"`
Version string `json:"version" required:"true" validate:"required"`
IsIPV6 bool `json:"is_ipv6,omitempty"`
Pools []pools.CreateOpts `json:"pools" required:"true" validate:"required,min=1,dive"`
Name string `json:"name" required:"true" validate:"required,gt=0,lte=20"`
Authentication *AuthenticationCreateOpts `json:"authentication,omitempty" validate:"omitempty"`
AutoscalerConfig map[string]string `json:"autoscaler_config,omitempty" validate:"omitempty"`
CNI *CNICreateOpts `json:"cni,omitempty" validate:"omitempty"`
FixedNetwork string `json:"fixed_network" validate:"omitempty,uuid4"`
FixedSubnet string `json:"fixed_subnet" validate:"omitempty,uuid4"`
PodsIPPool *gcorecloud.CIDR `json:"pods_ip_pool,omitempty" validate:"omitempty,cidr"`
ServicesIPPool *gcorecloud.CIDR `json:"services_ip_pool,omitempty" validate:"omitempty,cidr"`
PodsIPV6Pool *gcorecloud.CIDR `json:"pods_ipv6_pool,omitempty" validate:"omitempty,cidr"`
ServicesIPV6Pool *gcorecloud.CIDR `json:"services_ipv6_pool,omitempty" validate:"omitempty,cidr"`
KeyPair string `json:"keypair" required:"true" validate:"required"`
Version string `json:"version" required:"true" validate:"required"`
IsIPV6 bool `json:"is_ipv6,omitempty"`
Pools []pools.CreateOpts `json:"pools" required:"true" validate:"required,min=1,dive"`
}

// ToClusterCreateMap builds a request body from CreateOpts.
Expand All @@ -84,6 +103,27 @@ func (opts CreateOpts) ToClusterCreateMap() (map[string]interface{}, error) {
return gcorecloud.BuildRequestBody(opts, "")
}

type AuthenticationUpdateOpts = AuthenticationCreateOpts

// UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateOptsBuilder interface {
ToClusterUpdateMap() (map[string]interface{}, error)
}

// UpdateOpts represents options used to upgrade a cluster.
type UpdateOpts struct {
Authentication *AuthenticationUpdateOpts `json:"authentication,omitempty" validate:"omitempty"`
AutoscalerConfig map[string]string `json:"autoscaler_config,omitempty" validate:"omitempty"`
}

// ToClusterUpdateMap builds a request body from UpdateOpts.
func (opts UpdateOpts) ToClusterUpdateMap() (map[string]interface{}, error) {
if err := gcorecloud.ValidateStruct(opts); err != nil {
return nil, err
}
return gcorecloud.BuildRequestBody(opts, "")
}

// UpgradeOptsBuilder allows extensions to add additional parameters to the Upgrade request.
type UpgradeOptsBuilder interface {
ToClusterUpgradeMap() (map[string]interface{}, error)
Expand Down Expand Up @@ -186,6 +226,19 @@ func ListInstancesAll(c *gcorecloud.ServiceClient, clusterID string) ([]instance
return instances.ExtractInstances(page)
}

// Update accepts a UpdateOpts struct and updates an existing cluster using the values provided.
func Update(c *gcorecloud.ServiceClient, clusterID string, opts UpdateOptsBuilder) (r tasks.Result) {
b, err := opts.ToClusterUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Patch(updateURL(c, clusterID), b, &r.Body, &gcorecloud.RequestOpts{
OkCodes: []int{200, 201},
})
return
}

// Upgrade accepts a UpgradeOpts struct and upgrades an existing cluster using the values provided.
func Upgrade(c *gcorecloud.ServiceClient, clusterID string, opts UpgradeOptsBuilder) (r tasks.Result) {
b, err := opts.ToClusterUpgradeMap()
Expand Down
21 changes: 20 additions & 1 deletion gcore/k8s/v2/clusters/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,31 @@ type GetResult struct {
commonResult
}

type Authentication struct {
OIDC *OIDC `json:"oidc,omitempty"`
}

type OIDC struct {
ClientID string `json:"client_id,omitempty"`
GroupsClaim string `json:"groups_claim,omitempty"`
GroupsPrefix string `json:"groups_prefix,omitempty"`
IssuerURL string `json:"issuer_url,omitempty"`
RequiredClaims map[string]string `json:"required_claims,omitempty"`
SigningAlgs []string `json:"signing_algs,omitempty"`
UsernameClaim string `json:"username_claim,omitempty"`
UsernamePrefix string `json:"username_prefix,omitempty"`
}

type Cilium struct {
MaskSize int `json:"mask_size,omitempty"`
MaskSizeV6 int `json:"mask_size_v6,omitempty"`
Tunnel TunnelType `json:"tunnel,omitempty"`
Encryption bool `json:"encryption"`
LoadBalancerMode LBModeType `json:"lb_mode,omitemtpy"`
LoadBalancerMode LBModeType `json:"lb_mode,omitempty"`
LoadBalancerAcceleration bool `json:"lb_acceleration"`
RoutingMode RoutingModeType `json:"routing_mode,omitempty"`
HubbleRelay bool `json:"hubble_relay"`
HubbleUI bool `json:"hubble_ui"`
}

type CNI struct {
Expand All @@ -81,6 +98,8 @@ type Cluster struct {
Pools []pools.ClusterPool `json:"pools"`
Version string `json:"version"`
IsPublic bool `json:"is_public"`
Authentication *Authentication `json:"authentication,omitempty"`
AutoscalerConfig map[string]string `json:"autoscaler_config,omitempty"`
CNI *CNI `json:"cni,omitempty"`
FixedNetwork string `json:"fixed_network"`
FixedSubnet string `json:"fixed_subnet"`
Expand Down
4 changes: 4 additions & 0 deletions gcore/k8s/v2/clusters/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func getURL(c *gcorecloud.ServiceClient, clusterName string) string {
return resourceURL(c, clusterName)
}

func updateURL(c *gcorecloud.ServiceClient, clusterName string) string {
return resourceURL(c, clusterName)
}

func deleteURL(c *gcorecloud.ServiceClient, clusterName string) string {
return resourceURL(c, clusterName)
}
Expand Down
2 changes: 2 additions & 0 deletions gcore/k8s/v2/pools/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type CreateOpts struct {
IsPublicIPv4 bool `json:"is_public_ipv4,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Taints map[string]string `json:"taints,omitempty"`
CrioConfig map[string]string `json:"crio_config,omitempty" validate:"omitempty"`
KubeletConfig map[string]string `json:"kubelet_config,omitempty" validate:"omitempty"`
}

// Validate CreateOpts
Expand Down
2 changes: 2 additions & 0 deletions gcore/k8s/v2/pools/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type ClusterPool struct {
ServerGroupPolicy string `json:"servergroup_policy"`
Labels map[string]string `json:"labels,omitempty"`
Taints map[string]string `json:"taints,omitempty"`
CrioConfig map[string]string `json:"crio_config,omitempty"`
KubeletConfig map[string]string `json:"kubelet_config,omitempty"`
}

// ClusterPoolPage is the page returned by a pager when traversing over a
Expand Down

0 comments on commit fe85a2a

Please sign in to comment.