Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use optional fields for ClusterConfig #256

Merged
merged 40 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3dce7f0
checkpoint for new cluster config type
neoaggelos Mar 16, 2024
7e799eb
checkpoint defaults and merge
neoaggelos Mar 16, 2024
fcb2d2a
checkpoint cluster config validate
neoaggelos Mar 16, 2024
77cb59c
checkpoint add kubelet
neoaggelos Mar 16, 2024
f789482
update API optional fields
neoaggelos Mar 16, 2024
57e4123
checkpoint Empty() checks
neoaggelos Mar 16, 2024
02eec08
checkpoint finish converters
neoaggelos Mar 16, 2024
9a4ac10
Replace new types.ClusterConfig{}
neoaggelos Mar 17, 2024
94a3d50
update component cluster config use
neoaggelos Mar 17, 2024
bfb05b8
move conversion to user facing cluster config in types package
neoaggelos Mar 17, 2024
6f21d0a
cluster config validation moved to types package
neoaggelos Mar 17, 2024
80c16c7
marshal cluster config as json
neoaggelos Mar 17, 2024
9738401
update api and hooks for new cluster config
neoaggelos Mar 17, 2024
99e7bd9
update cli for new cluster config types
neoaggelos Mar 17, 2024
0d41fa7
default values for all cluster config fields
neoaggelos Mar 17, 2024
b3c646e
fix k8s get output
neoaggelos Mar 17, 2024
5b25faa
embed feature configs
neoaggelos Mar 17, 2024
13a460d
tidy usage of API fields
neoaggelos Mar 17, 2024
326ad0b
revert parse_test.go testing code
neoaggelos Mar 17, 2024
fa2d2d8
enable l2-mode on loadbalancer
neoaggelos Mar 17, 2024
a10ca8f
move all validations into `(*ClusterConfig).Validate()` and update go…
neoaggelos Mar 24, 2024
82d10fb
update config to v1alpha2
neoaggelos Mar 24, 2024
5100060
fix k8s status output
neoaggelos Mar 24, 2024
29a4b66
Merge branch 'main' into dev/checkpoint/cluster-config
neoaggelos Mar 29, 2024
199e052
update util functions for new cluster config
neoaggelos Apr 1, 2024
9c3be1c
fixup usage of new clusterconfig types
neoaggelos Apr 1, 2024
cb85d54
yaml omitempty and update tests
neoaggelos Apr 1, 2024
373f30e
handle empty config in k8s status output
neoaggelos Apr 2, 2024
8e51da5
debug tests
neoaggelos Apr 2, 2024
9612108
fixup dns configuration on bootstrap
neoaggelos Apr 2, 2024
efa52af
Merge branch 'main' into dev/checkpoint/cluster-config
neoaggelos Apr 2, 2024
5f44a51
make the node configuration forward-edge
neoaggelos Apr 3, 2024
38fe028
fix handling of nil and empty values for node controller
neoaggelos Apr 3, 2024
8a4570a
update node configuration controller test
neoaggelos Apr 3, 2024
b295947
expect err to be nil, not succeed
neoaggelos Apr 3, 2024
2aef36b
explain how kubelet args are updated
neoaggelos Apr 3, 2024
793b30c
Merge branch 'main' into dev/checkpoint/cluster-config
neoaggelos Apr 3, 2024
b279d69
Merge branch 'main' into dev/checkpoint/cluster-config
neoaggelos Apr 3, 2024
ffca655
cleanup conversion from internal cluster config -> API
neoaggelos Apr 3, 2024
c8bbe8c
validate load balancer CIDRs
neoaggelos Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 61 additions & 31 deletions src/k8s/api/v1/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,89 @@ type UpdateClusterConfigResponse struct {
}

type UserFacingClusterConfig struct {
Network *NetworkConfig `json:"network,omitempty" yaml:"network,omitempty"`
DNS *DNSConfig `json:"dns,omitempty" yaml:"dns,omitempty"`
Ingress *IngressConfig `json:"ingress,omitempty" yaml:"ingress,omitempty"`
LoadBalancer *LoadBalancerConfig `json:"load-balancer,omitempty" yaml:"load-balancer,omitempty"`
LocalStorage *LocalStorageConfig `json:"local-storage,omitempty" yaml:"local-storage,omitempty"`
Gateway *GatewayConfig `json:"gateway,omitempty" yaml:"gateway,omitempty"`
MetricsServer *MetricsServerConfig `json:"metrics-server,omitempty" yaml:"metrics-server,omitempty"`
Network NetworkConfig `json:"network,omitempty" yaml:"network,omitempty"`
DNS DNSConfig `json:"dns,omitempty" yaml:"dns,omitempty"`
Ingress IngressConfig `json:"ingress,omitempty" yaml:"ingress,omitempty"`
LoadBalancer LoadBalancerConfig `json:"load-balancer,omitempty" yaml:"load-balancer,omitempty"`
LocalStorage LocalStorageConfig `json:"local-storage,omitempty" yaml:"local-storage,omitempty"`
Gateway GatewayConfig `json:"gateway,omitempty" yaml:"gateway,omitempty"`
MetricsServer MetricsServerConfig `json:"metrics-server,omitempty" yaml:"metrics-server,omitempty"`
}

type DNSConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
ClusterDomain string `json:"cluster-domain,omitempty" yaml:"cluster-domain"`
ServiceIP string `json:"service-ip,omitempty" yaml:"service-ip"`
UpstreamNameservers []string `json:"upstream-nameservers,omitempty" yaml:"upstream-nameservers"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
ClusterDomain *string `json:"cluster-domain,omitempty" yaml:"cluster-domain,omitempty"`
ServiceIP *string `json:"service-ip,omitempty" yaml:"service-ip,omitempty"`
UpstreamNameservers *[]string `json:"upstream-nameservers,omitempty" yaml:"upstream-nameservers,omitempty"`
}

func (c DNSConfig) GetEnabled() bool { return getField(c.Enabled) }
func (c DNSConfig) GetClusterDomain() string { return getField(c.ClusterDomain) }
func (c DNSConfig) GetServiceIP() string { return getField(c.ServiceIP) }
func (c DNSConfig) GetUpstreamNameservers() []string { return getField(c.UpstreamNameservers) }

type IngressConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
DefaultTLSSecret string `json:"default-tls-secret,omitempty" yaml:"default-tls-secret"`
EnableProxyProtocol *bool `json:"enable-proxy-protocol,omitempty" yaml:"enable-proxy-protocol"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
DefaultTLSSecret *string `json:"default-tls-secret,omitempty" yaml:"default-tls-secret,omitempty"`
EnableProxyProtocol *bool `json:"enable-proxy-protocol,omitempty" yaml:"enable-proxy-protocol,omitempty"`
}

func (c IngressConfig) GetEnabled() bool { return getField(c.Enabled) }
func (c IngressConfig) GetDefaultTLSSecret() string { return getField(c.DefaultTLSSecret) }
func (c IngressConfig) GetEnableProxyProtocol() bool { return getField(c.EnableProxyProtocol) }

type LoadBalancerConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
CIDRs []string `json:"cidrs,omitempty" yaml:"cidrs"`
L2Enabled *bool `json:"l2-mode,omitempty" yaml:"l2-mode"`
L2Interfaces []string `json:"l2-interfaces,omitempty" yaml:"l2-interfaces"`
BGPEnabled *bool `json:"bgp-mode,omitempty" yaml:"bgp-mode"`
BGPLocalASN int `json:"bgp-local-asn,omitempty" yaml:"bgp-local-asn"`
BGPPeerAddress string `json:"bgp-peer-address,omitempty" yaml:"bgp-peer-address"`
BGPPeerASN int `json:"bgp-peer-asn,omitempty" yaml:"bgp-peer-asn"`
BGPPeerPort int `json:"bgp-peer-port,omitempty" yaml:"bgp-peer-port"`
}
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
CIDRs *[]string `json:"cidrs,omitempty" yaml:"cidrs,omitempty"`
L2Mode *bool `json:"l2-mode,omitempty" yaml:"l2-mode,omitempty"`
L2Interfaces *[]string `json:"l2-interfaces,omitempty" yaml:"l2-interfaces,omitempty"`
BGPMode *bool `json:"bgp-mode,omitempty" yaml:"bgp-mode,omitempty"`
BGPLocalASN *int `json:"bgp-local-asn,omitempty" yaml:"bgp-local-asn,omitempty"`
BGPPeerAddress *string `json:"bgp-peer-address,omitempty" yaml:"bgp-peer-address,omitempty"`
BGPPeerASN *int `json:"bgp-peer-asn,omitempty" yaml:"bgp-peer-asn,omitempty"`
BGPPeerPort *int `json:"bgp-peer-port,omitempty" yaml:"bgp-peer-port,omitempty"`
}

func (c LoadBalancerConfig) GetEnabled() bool { return getField(c.Enabled) }
func (c LoadBalancerConfig) GetCIDRs() []string { return getField(c.CIDRs) }
func (c LoadBalancerConfig) GetL2Mode() bool { return getField(c.L2Mode) }
func (c LoadBalancerConfig) GetL2Interfaces() []string { return getField(c.L2Interfaces) }
func (c LoadBalancerConfig) GetBGPMode() bool { return getField(c.BGPMode) }
func (c LoadBalancerConfig) GetBGPLocalASN() int { return getField(c.BGPLocalASN) }
func (c LoadBalancerConfig) GetBGPPeerAddress() string { return getField(c.BGPPeerAddress) }
func (c LoadBalancerConfig) GetBGPPeerASN() int { return getField(c.BGPPeerASN) }
func (c LoadBalancerConfig) GetBGPPeerPort() int { return getField(c.BGPPeerPort) }

type LocalStorageConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
LocalPath string `json:"local-path,omitempty" yaml:"local-path"`
ReclaimPolicy string `json:"reclaim-policy,omitempty" yaml:"reclaim-policy"`
SetDefault *bool `json:"set-default,omitempty" yaml:"set-default"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
LocalPath *string `json:"local-path,omitempty" yaml:"local-path,omitempty"`
ReclaimPolicy *string `json:"reclaim-policy,omitempty" yaml:"reclaim-policy,omitempty"`
SetDefault *bool `json:"set-default,omitempty" yaml:"set-default,omitempty"`
}

func (c LocalStorageConfig) GetEnabled() bool { return getField(c.Enabled) }
func (c LocalStorageConfig) GetLocalPath() string { return getField(c.LocalPath) }
func (c LocalStorageConfig) GetReclaimPolicy() string { return getField(c.ReclaimPolicy) }
func (c LocalStorageConfig) GetSetDefault() bool { return getField(c.SetDefault) }

type NetworkConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

func (c NetworkConfig) GetEnabled() bool { return getField(c.Enabled) }

type GatewayConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

func (c GatewayConfig) GetEnabled() bool { return getField(c.Enabled) }

type MetricsServerConfig struct {
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

func (c MetricsServerConfig) GetEnabled() bool { return getField(c.Enabled) }

func (c UserFacingClusterConfig) String() string {
b, err := yaml.Marshal(c)
if err != nil {
Expand Down
31 changes: 3 additions & 28 deletions src/k8s/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,35 +170,10 @@ func (c ClusterStatus) String() string {
result.WriteString(" spare-nodes: none\n")
}

printedConfig := UserFacingClusterConfig{}
if c.Config.Network != nil && c.Config.Network.Enabled != nil && *c.Config.Network.Enabled {
printedConfig.Network = c.Config.Network
}
if c.Config.DNS != nil && c.Config.DNS.Enabled != nil && *c.Config.DNS.Enabled {
printedConfig.DNS = c.Config.DNS
}
if c.Config.Ingress != nil && c.Config.Ingress.Enabled != nil && *c.Config.Ingress.Enabled {
printedConfig.Ingress = c.Config.Ingress
}
if c.Config.LoadBalancer != nil && c.Config.LoadBalancer.Enabled != nil && *c.Config.LoadBalancer.Enabled {
printedConfig.LoadBalancer = c.Config.LoadBalancer
}
if c.Config.LocalStorage != nil && c.Config.LocalStorage.Enabled != nil && *c.Config.LocalStorage.Enabled {
printedConfig.LocalStorage = c.Config.LocalStorage
}
if c.Config.Gateway != nil && c.Config.Gateway.Enabled != nil && *c.Config.Gateway.Enabled {
printedConfig.Gateway = c.Config.Gateway
}
if c.Config.MetricsServer != nil && c.Config.MetricsServer.Enabled != nil && *c.Config.MetricsServer.Enabled {
printedConfig.MetricsServer = c.Config.MetricsServer
}

b, _ := yaml.Marshal(printedConfig)
// If no config is set the marshalling will return {}
if s := string(b); s != "{}\n" {
result.WriteString("\n")
var emptyConfig UserFacingClusterConfig
if c.Config != emptyConfig {
b, _ := yaml.Marshal(c.Config)
result.WriteString(string(b))
}

return result.String()
}
11 changes: 3 additions & 8 deletions src/k8s/api/v1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ func TestHaClusterFormed(t *testing.T) {
}

func TestString(t *testing.T) {
g := NewGomegaWithT(t)

testCases := []struct {
name string
clusterStatus ClusterStatus
Expand All @@ -114,8 +112,8 @@ func TestString(t *testing.T) {
{Name: "node3", DatastoreRole: DatastoreRoleVoter, Address: "192.168.0.3"},
},
Config: UserFacingClusterConfig{
Network: &NetworkConfig{Enabled: vals.Pointer(true)},
DNS: &DNSConfig{Enabled: vals.Pointer(true)},
Network: NetworkConfig{Enabled: vals.Pointer(true)},
DNS: DNSConfig{Enabled: vals.Pointer(true)},
},
},
expectedOutput: `status: ready
Expand All @@ -127,14 +125,10 @@ datastore:
- 192.168.0.3
standby-nodes: none
spare-nodes: none

network:
enabled: true
dns:
enabled: true
cluster-domain: ""
service-ip: ""
upstream-nameservers: []
`,
},
{
Expand All @@ -156,6 +150,7 @@ datastore:

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
g.Expect(tc.clusterStatus.String()).To(Equal(tc.expectedOutput))
})
}
Expand Down
9 changes: 9 additions & 0 deletions src/k8s/api/v1/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

func getField[T any](val *T) T {
if val != nil {
return *val
}
var zero T
return zero
}
14 changes: 7 additions & 7 deletions src/k8s/cmd/k8s/k8s_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ func newDisableCmd(env cmdutil.ExecutionEnvironment) *cobra.Command {

switch functionality {
case "network":
config.Network = &api.NetworkConfig{
config.Network = api.NetworkConfig{
Enabled: vals.Pointer(false),
}
case "dns":
config.DNS = &api.DNSConfig{
config.DNS = api.DNSConfig{
Enabled: vals.Pointer(false),
}
case "gateway":
config.Gateway = &api.GatewayConfig{
config.Gateway = api.GatewayConfig{
Enabled: vals.Pointer(false),
}
case "ingress":
config.Ingress = &api.IngressConfig{
config.Ingress = api.IngressConfig{
Enabled: vals.Pointer(false),
}
case "local-storage":
config.LocalStorage = &api.LocalStorageConfig{
config.LocalStorage = api.LocalStorageConfig{
Enabled: vals.Pointer(false),
}
case "load-balancer":
config.LoadBalancer = &api.LoadBalancerConfig{
config.LoadBalancer = api.LoadBalancerConfig{
Enabled: vals.Pointer(false),
}
case "metrics-server":
config.MetricsServer = &api.MetricsServerConfig{
config.MetricsServer = api.MetricsServerConfig{
Enabled: vals.Pointer(false),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/k8s/cmd/k8s/k8s_disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestDisableCmd(t *testing.T) {
funcs: []string{"gateway"},
expectedCall: apiv1.UpdateClusterConfigRequest{
Config: apiv1.UserFacingClusterConfig{
Gateway: &apiv1.GatewayConfig{Enabled: vals.Pointer(false)},
Gateway: apiv1.GatewayConfig{Enabled: vals.Pointer(false)},
},
},
expectedStdout: "disabled",
Expand All @@ -44,8 +44,8 @@ func TestDisableCmd(t *testing.T) {
funcs: []string{"load-balancer", "gateway"},
expectedCall: apiv1.UpdateClusterConfigRequest{
Config: apiv1.UserFacingClusterConfig{
Gateway: &apiv1.GatewayConfig{Enabled: vals.Pointer(false)},
LoadBalancer: &apiv1.LoadBalancerConfig{Enabled: vals.Pointer(false)},
Gateway: apiv1.GatewayConfig{Enabled: vals.Pointer(false)},
LoadBalancer: apiv1.LoadBalancerConfig{Enabled: vals.Pointer(false)},
},
},
expectedStdout: "disabled",
Expand Down
14 changes: 7 additions & 7 deletions src/k8s/cmd/k8s/k8s_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ func newEnableCmd(env cmdutil.ExecutionEnvironment) *cobra.Command {

switch functionality {
case "network":
config.Network = &api.NetworkConfig{
config.Network = api.NetworkConfig{
Enabled: vals.Pointer(true),
}
case "dns":
config.DNS = &api.DNSConfig{
config.DNS = api.DNSConfig{
Enabled: vals.Pointer(true),
}
case "gateway":
config.Gateway = &api.GatewayConfig{
config.Gateway = api.GatewayConfig{
Enabled: vals.Pointer(true),
}
case "ingress":
config.Ingress = &api.IngressConfig{
config.Ingress = api.IngressConfig{
Enabled: vals.Pointer(true),
}
case "local-storage":
config.LocalStorage = &api.LocalStorageConfig{
config.LocalStorage = api.LocalStorageConfig{
Enabled: vals.Pointer(true),
}
case "load-balancer":
config.LoadBalancer = &api.LoadBalancerConfig{
config.LoadBalancer = api.LoadBalancerConfig{
Enabled: vals.Pointer(true),
}
case "metrics-server":
config.MetricsServer = &api.MetricsServerConfig{
config.MetricsServer = api.MetricsServerConfig{
Enabled: vals.Pointer(true),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/k8s/cmd/k8s/k8s_enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestK8sEnableCmd(t *testing.T) {
funcs: []string{"gateway"},
expectedCall: apiv1.UpdateClusterConfigRequest{
Config: apiv1.UserFacingClusterConfig{
Gateway: &apiv1.GatewayConfig{Enabled: vals.Pointer(true)},
Gateway: apiv1.GatewayConfig{Enabled: vals.Pointer(true)},
},
},
expectedStdout: "enabled",
Expand All @@ -44,8 +44,8 @@ func TestK8sEnableCmd(t *testing.T) {
funcs: []string{"load-balancer", "gateway"},
expectedCall: apiv1.UpdateClusterConfigRequest{
Config: apiv1.UserFacingClusterConfig{
Gateway: &apiv1.GatewayConfig{Enabled: vals.Pointer(true)},
LoadBalancer: &apiv1.LoadBalancerConfig{Enabled: vals.Pointer(true)},
Gateway: apiv1.GatewayConfig{Enabled: vals.Pointer(true)},
LoadBalancer: apiv1.LoadBalancerConfig{Enabled: vals.Pointer(true)},
},
},
expectedStdout: "enabled",
Expand Down
Loading
Loading