Skip to content

Commit 3d735a2

Browse files
authored
Restore k0s spec.api.sans updating that was removed in #772 (#783)
* Restore sans manipulation that was removed in #772 Signed-off-by: Kimmo Lehto <[email protected]> * Make sans global Signed-off-by: Kimmo Lehto <[email protected]> --------- Signed-off-by: Kimmo Lehto <[email protected]>
1 parent fa88107 commit 3d735a2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

phase/configure_k0s.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
gopath "path"
8+
"slices"
89
"time"
910

1011
"github.com/k0sproject/dig"
@@ -74,6 +75,42 @@ func (p *ConfigureK0s) Prepare(config *v1beta1.Cluster) error {
7475
}
7576
}
7677

78+
// convert sans from unmarshaled config into []string
79+
var sans []string
80+
oldsans := p.newBaseConfig.Dig("spec", "api", "sans")
81+
switch oldsans := oldsans.(type) {
82+
case []interface{}:
83+
for _, v := range oldsans {
84+
if s, ok := v.(string); ok {
85+
sans = append(sans, s)
86+
}
87+
}
88+
log.Tracef("converted sans from %T to []string", oldsans)
89+
case []string:
90+
sans = append(sans, oldsans...)
91+
log.Tracef("sans was readily %T", oldsans)
92+
default:
93+
// do nothing - base k0s config does not contain any existing SANs
94+
}
95+
96+
// populate SANs with all controller addresses
97+
for i, c := range p.Config.Spec.Hosts.Controllers() {
98+
if c.Reset {
99+
continue
100+
}
101+
if !slices.Contains(sans, c.Address()) {
102+
sans = append(sans, c.Address())
103+
log.Debugf("added controller %d address %s to spec.api.sans", i+1, c.Address())
104+
}
105+
if c.PrivateAddress != "" && !slices.Contains(sans, c.PrivateAddress) {
106+
sans = append(sans, c.PrivateAddress)
107+
log.Debugf("added controller %d private address %s to spec.api.sans", i+1, c.PrivateAddress)
108+
}
109+
}
110+
111+
// assign populated sans to the base config
112+
p.newBaseConfig.DigMapping("spec", "api")["sans"] = sans
113+
77114
for _, h := range p.Config.Spec.Hosts.Controllers() {
78115
if h.Reset {
79116
continue
@@ -286,6 +323,7 @@ func (p *ConfigureK0s) configFor(h *cluster.Host) (string, error) {
286323
}
287324

288325
var addr string
326+
289327
if h.PrivateAddress != "" {
290328
addr = h.PrivateAddress
291329
} else {

0 commit comments

Comments
 (0)