Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Commit

Permalink
fix: validate cluster endpoint
Browse files Browse the repository at this point in the history
Validates cluster endpoint from v1alpha1 config.

Fixes siderolabs#2101

Signed-off-by: Seán C McCord <[email protected]>
  • Loading branch information
Ulexus authored and talos-bot committed Sep 17, 2020
1 parent 551ab70 commit 3db5f72
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require (
github.com/talos-systems/go-retry v0.1.0
github.com/talos-systems/go-smbios v0.0.0-20200219201045-94b8c4e489ee
github.com/talos-systems/grpc-proxy v0.2.0
github.com/talos-systems/net v0.1.0
github.com/talos-systems/net v0.2.0
github.com/talos-systems/talos/pkg/machinery v0.0.0-20200818212414-6a7cc0264819
github.com/u-root/u-root v6.0.0+incompatible // indirect
github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ github.com/talos-systems/go-smbios v0.0.0-20200219201045-94b8c4e489ee h1:9i0ZFsj
github.com/talos-systems/go-smbios v0.0.0-20200219201045-94b8c4e489ee/go.mod h1:HxhrzAoTZ7ed5Z5VvtCvnCIrOxyXDS7V2B5hCetAMW8=
github.com/talos-systems/grpc-proxy v0.2.0 h1:DN75bLfaW4xfhq0r0mwFRnfGhSB+HPhK1LNzuMEs9Pw=
github.com/talos-systems/grpc-proxy v0.2.0/go.mod h1:sm97Vc/z2cok3pu6ruNeszQej4KDxFrDgfWs4C1mtC4=
github.com/talos-systems/net v0.1.0 h1:fEgj3xbH+lIopFGnk/4CaV4QvFG2kQXs/t+pfeZGmCc=
github.com/talos-systems/net v0.1.0/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/talos-systems/net v0.2.0 h1:QJ2ofYboG1Zjew9b+3RAjtLIfL0mIONGuc6/LyO68MM=
github.com/talos-systems/net v0.2.0/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
29 changes: 23 additions & 6 deletions pkg/machinery/config/types/v1alpha1/v1alpha1_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/hashicorp/go-multierror"

talosnet "github.com/talos-systems/net"

"github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/constants"
Expand Down Expand Up @@ -64,12 +66,8 @@ func (c *Config) Validate(mode config.RuntimeMode) error {
result = multierror.Append(result, errors.New("machine instructions are required"))
}

if c.ClusterConfig == nil {
result = multierror.Append(result, errors.New("cluster instructions are required"))
}

if c.Cluster().Endpoint() == nil || c.Cluster().Endpoint().String() == "" {
result = multierror.Append(result, errors.New("a cluster endpoint is required"))
if err := c.ClusterConfig.Validate(); err != nil {
result = multierror.Append(result, err)
}

if mode.RequiresInstall() {
Expand Down Expand Up @@ -120,6 +118,25 @@ func (c *Config) Validate(mode config.RuntimeMode) error {
return result.ErrorOrNil()
}

// Validate validates the config.
func (c *ClusterConfig) Validate() error {
var result *multierror.Error

if c == nil {
return fmt.Errorf("cluster instructions are required")
}

if c.ControlPlane == nil || c.ControlPlane.Endpoint == nil {
return fmt.Errorf("cluster controlplane endpoint is required")
}

if err := talosnet.ValidateEndpointURI(c.ControlPlane.Endpoint.URL.String()); err != nil {
result = multierror.Append(result, fmt.Errorf("invalid controlplane endpoint: %w", err))
}

return result.ErrorOrNil()
}

// ValidateNetworkDevices runs the specified validation checks specific to the
// network devices.
//nolint: dupl
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/talos-systems/bootkube-plugin v0.0.0-20200729203641-12d463a3e54e
github.com/talos-systems/crypto v0.2.0
github.com/talos-systems/net v0.1.0
github.com/talos-systems/net v0.2.0
google.golang.org/grpc v1.29.0
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
Expand Down
4 changes: 2 additions & 2 deletions pkg/machinery/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ github.com/talos-systems/bootkube-plugin v0.0.0-20200729203641-12d463a3e54e h1:Z
github.com/talos-systems/bootkube-plugin v0.0.0-20200729203641-12d463a3e54e/go.mod h1:AbdJAgHK5rJNDPUN3msPTfQJSR9b4DKb5xNN07uG8/Y=
github.com/talos-systems/crypto v0.2.0 h1:UwT8uhJ0eDlklY0vYwo1+LGoFgiqkPqjQnae6j8UNYE=
github.com/talos-systems/crypto v0.2.0/go.mod h1:KwqG+jANKU1FNQIapmioHQ5fkovY1DJkAqMenjYBGh0=
github.com/talos-systems/net v0.1.0 h1:fEgj3xbH+lIopFGnk/4CaV4QvFG2kQXs/t+pfeZGmCc=
github.com/talos-systems/net v0.1.0/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/talos-systems/net v0.2.0 h1:QJ2ofYboG1Zjew9b+3RAjtLIfL0mIONGuc6/LyO68MM=
github.com/talos-systems/net v0.2.0/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
Expand Down

0 comments on commit 3db5f72

Please sign in to comment.