Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
[6.1.x] always create ClusterConfiguration resource on install (#1864)
Browse files Browse the repository at this point in the history
* Add guard blocks to avoid use of nil interface
* Always generate cluster configuration based on CLI flags even if only    from default values
* Include pod/service CIDR values in text output of 'gravity resource get'
* Move podCIDR/serviceCIDR separate values to cluster configuration on configuration early on. This will remove the need to handle these attributes separately
* Run resource validation early also on cluster configuration resource during installation
* Address review comments
  • Loading branch information
a-palchikov authored Jul 13, 2020
1 parent 3aa47ca commit b93cda4
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 86 deletions.
2 changes: 1 addition & 1 deletion e
Submodule e updated from 35b84c to 594532
10 changes: 3 additions & 7 deletions lib/install/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ type Config struct {
// SiteDomain is the name of the cluster
SiteDomain string
// Flavor is installation flavor
Flavor *schema.Flavor
Flavor schema.Flavor
// Role is server role
Role string
// App is the application being installed
App *app.Application
App app.Application
// RuntimeResources specifies optional Kubernetes resources to create
RuntimeResources []runtime.Object
// ClusterResources specifies optional cluster resources to create
Expand All @@ -103,10 +103,6 @@ type Config struct {
Mounts map[string]string
// DNSOverrides contains installer node DNS overrides
DNSOverrides storage.DNSOverrides
// PodCIDR is a pod network CIDR
PodCIDR string
// ServiceCIDR is a service network CIDR
ServiceCIDR string
// VxlanPort is the overlay network port
VxlanPort int
// DNSConfig overrides the local cluster DNS configuration
Expand Down Expand Up @@ -169,7 +165,7 @@ func (c *Config) checkAndSetDefaults() (err error) {
if c.LocalBackend == nil {
return trace.BadParameter("missing LocalBackend")
}
if c.App == nil {
if c.App.Package.IsEmpty() {
return trace.BadParameter("missing App")
}
if c.DNSConfig.IsEmpty() {
Expand Down
6 changes: 2 additions & 4 deletions lib/install/engine/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ func (r *executor) createOperation() (*ops.SiteOperation, error) {
Docker: r.config.Docker,
},
OnPrem: storage.OnPremVariables{
PodCIDR: r.config.PodCIDR,
ServiceCIDR: r.config.ServiceCIDR,
VxlanPort: r.config.VxlanPort,
VxlanPort: r.config.VxlanPort,
},
},
Profiles: install.ServerRequirements(*r.config.Flavor),
Profiles: install.ServerRequirements(r.config.Flavor),
})
if err != nil {
return nil, trace.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/ops/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *AgentReport) Diff(previous *AgentReport) (added, removed []checks.Serve
//
// Returns number/roles of agents that still need to join as well as any
// extra servers that are not a part of the flavor.
func (s *AgentReport) MatchFlavor(flavor *schema.Flavor) (needed map[string]int, extra []checks.ServerInfo) {
func (s *AgentReport) MatchFlavor(flavor schema.Flavor) (needed map[string]int, extra []checks.ServerInfo) {
needed = make(map[string]int)
for _, node := range flavor.Nodes {
needed[node.Profile] = node.Count
Expand Down
2 changes: 1 addition & 1 deletion lib/ops/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *AgentReportSuite) TestCheck(c *check.C) {
Servers: []checks.ServerInfo{server1, server2, server3},
}

needed, extra := report.MatchFlavor(&schema.Flavor{
needed, extra := report.MatchFlavor(schema.Flavor{
Nodes: []schema.FlavorNode{
{Profile: "worker", Count: 3},
{Profile: "db", Count: 2},
Expand Down
20 changes: 14 additions & 6 deletions lib/ops/opsservice/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ func (s *site) configurePackages(ctx *operationContext, req ops.ConfigurePackage

etcdConfig := s.prepareEtcdConfig(ctx)

var clusterConfig clusterconfig.Interface
clusterConfig := clusterconfig.NewEmpty()
if len(req.Config) != 0 {
clusterConfig, err = clusterconfig.Unmarshal(req.Config)
if err != nil {
return trace.Wrap(err)
}
if s.cloudProviderName() != "" {
clusterConfig.SetCloudProvider(s.cloudProviderName())
}
}
if s.cloudProviderName() != "" {
clusterConfig.SetCloudProvider(s.cloudProviderName())
}

for i, master := range masters {
Expand Down Expand Up @@ -1037,11 +1037,19 @@ func (s *site) configurePlanetServer(config planetConfig) error {
}

func (r planetConfig) podSubnet() string {
return podSubnet(r.installExpand.InstallExpand, r.config.GetGlobalConfig().PodCIDR)
var override string
if r.config != nil {
override = r.config.GetGlobalConfig().PodCIDR
}
return podSubnet(r.installExpand.InstallExpand, override)
}

func (r planetConfig) serviceSubnet() string {
return serviceSubnet(r.installExpand.InstallExpand, r.config.GetGlobalConfig().ServiceCIDR)
var override string
if r.config != nil {
override = r.config.GetGlobalConfig().ServiceCIDR
}
return serviceSubnet(r.installExpand.InstallExpand, override)
}

type planetConfig struct {
Expand Down
20 changes: 13 additions & 7 deletions lib/ops/resources/gravity/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,13 +664,11 @@ func (r configCollection) WriteText(w io.Writer) error {
fmt.Fprintf(t, "%v\n", string(config.Config))
}
config := r.GetGlobalConfig()
displayCloudConfig := config.CloudProvider != "" || config.CloudConfig != ""
if displayCloudConfig {
common.PrintCustomTableHeader(t, []string{"Cloud"}, "-")
if len(config.CloudProvider) != 0 {
fmt.Fprintf(t, "Provider:\t%v\n", config.CloudProvider)
}
formatCloudConfig(t, config.CloudConfig)
if len(config.PodCIDR) != 0 {
fmt.Fprintf(t, "Pod IP Range:\t%v\n", config.PodCIDR)
}
if len(config.ServiceCIDR) != 0 {
fmt.Fprintf(t, "Service IP Range:\t%v\n", config.ServiceCIDR)
}
if len(config.ServiceNodePortRange) != 0 {
fmt.Fprintf(t, "Service Node Port Range:\t%v\n", config.ServiceNodePortRange)
Expand All @@ -681,6 +679,14 @@ func (r configCollection) WriteText(w io.Writer) error {
if len(config.FeatureGates) != 0 {
fmt.Fprintf(t, "Feature Gates:\t%v\n", formatFeatureGates(config.FeatureGates))
}
displayCloudConfig := config.CloudProvider != "" || config.CloudConfig != ""
if displayCloudConfig {
common.PrintCustomTableHeader(t, []string{"Cloud"}, "-")
if len(config.CloudProvider) != 0 {
fmt.Fprintf(t, "Provider:\t%v\n", config.CloudProvider)
}
formatCloudConfig(t, config.CloudConfig)
}
_, err := io.WriteString(w, t.String())
return trace.Wrap(err)
}
Expand Down
8 changes: 7 additions & 1 deletion lib/ops/resources/gravity/gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/gravitational/gravity/lib/ops/resources"
"github.com/gravitational/gravity/lib/storage"
"github.com/gravitational/gravity/lib/storage/clusterconfig"
"github.com/gravitational/gravity/lib/validate"

"github.com/fatih/color"
teleservices "github.com/gravitational/teleport/lib/services"
Expand Down Expand Up @@ -559,7 +560,12 @@ func Validate(resource storage.UnknownResource) (err error) {
case storage.KindRuntimeEnvironment:
_, err = storage.UnmarshalEnvironmentVariables(resource.Raw)
case storage.KindClusterConfiguration:
_, err = clusterconfig.Unmarshal(resource.Raw)
config, err := clusterconfig.Unmarshal(resource.Raw)
if err != nil {
return trace.Wrap(err)
}
globalConfig := config.GetGlobalConfig()
return validate.KubernetesSubnetsFromStrings(globalConfig.PodCIDR, globalConfig.ServiceCIDR)
default:
return trace.NotImplemented("unsupported resource %q, supported are: %v",
resource.Kind, modules.GetResources().SupportedResources())
Expand Down
7 changes: 7 additions & 0 deletions lib/storage/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Interface interface {
GetKubeletConfig() *Kubelet
// GetGlobalConfig returns the global configuration
GetGlobalConfig() Global
// SetGlobalConfig sets the new global configuration
SetGlobalConfig(Global)
// SetCloudProvider sets the cloud provider for this configuration
SetCloudProvider(provider string)
}
Expand Down Expand Up @@ -111,6 +113,11 @@ func (r *Resource) GetGlobalConfig() Global {
return r.Spec.Global
}

// SetGlobalConfig sets the new global configuration
func (r *Resource) SetGlobalConfig(config Global) {
r.Spec.Global = config
}

// SetCloudProvider sets the cloud provider for this configuration
func (r *Resource) SetCloudProvider(provider string) {
r.Spec.Global.CloudProvider = provider
Expand Down
10 changes: 10 additions & 0 deletions lib/validate/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ func KubernetesSubnets(podNet, serviceNet *net.IPNet) (err error) {
}
return nil
}

// NormalizeSubnet returns the text representation of the given subnet
// as the IP masked with the network mask
func NormalizeSubnet(subnet string) (string, error) {
_, ipNet, err := net.ParseCIDR(subnet)
if err != nil {
return "", trace.Wrap(err)
}
return ipNet.String(), nil
}
Loading

0 comments on commit b93cda4

Please sign in to comment.