Skip to content

Commit

Permalink
Update Kube API tests to handle BindAddress
Browse files Browse the repository at this point in the history
Signed-off-by: gakio12 <gakio12@gmail.com>
  • Loading branch information
gakio12 committed Nov 7, 2021
1 parent c992203 commit 0a7f388
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (c *CmdOpts) startController(ctx context.Context) error {
})

logrus.Infof("using api address: %s", c.NodeConfig.Spec.API.Address)
logrus.Infof("using api bind-address: %s", c.NodeConfig.Spec.API.BindAddress)
logrus.Infof("using listen port: %d", c.NodeConfig.Spec.API.Port)
logrus.Infof("using sans: %s", c.NodeConfig.Spec.API.SANs)
dnsAddress, err := c.NodeConfig.Spec.Network.DNSAddress()
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/k0s.k0sproject.io/v1beta1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type APISpec struct {
// Local address on which to bind an API
Address string `json:"address"`

// Local address on which to bind the kube-apiserver. Defaults to 0.0.0.0.
BindAddress string `json:"bindAddress,omitempty"`

// The loadbalancer address (for k0s controllers running behind a loadbalancer)
ExternalAddress string `json:"externalAddress,omitempty"`

Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/k0s.k0sproject.io/v1beta1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (s *APISuite) TestValidation() {
s.T().Run("accepts_ipv6_as_address", func(t *testing.T) {
a := APISpec{
Address: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
BindAddress: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
}

s.Nil(a.Validate())
Expand All @@ -44,6 +45,7 @@ func (s *APISuite) TestValidation() {
s.T().Run("invalid_api_address", func(t *testing.T) {
a := APISpec{
Address: "somehting.that.is.not.valid//(())",
BindAddress: "0.0.0.0",
}

errors := a.Validate()
Expand All @@ -55,6 +57,7 @@ func (s *APISuite) TestValidation() {
s.T().Run("invalid_sans_address", func(t *testing.T) {
a := APISpec{
Address: "1.2.3.4",
BindAddress: "0.0.0.0",
SANs: []string{
"somehting.that.is.not.valid//(())",
},
Expand All @@ -65,6 +68,18 @@ func (s *APISuite) TestValidation() {
s.Len(errors, 1)
s.Contains(errors[0].Error(), "is not a valid address for sans")
})

s.T().Run("invalid_api_bind_address", func(t *testing.T) {
a := APISpec{
Address: "1.2.3.4",
BindAddress: "somehting.that.is.not.valid//(())",
}

errors := a.Validate()
s.NotNil(errors)
s.Len(errors, 1)
s.Contains(errors[0].Error(), "is not IP address")
})
}

func TestApiSuite(t *testing.T) {
Expand Down

0 comments on commit 0a7f388

Please sign in to comment.