Skip to content

Commit

Permalink
Simplify, no need for pointers
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Nov 4, 2024
1 parent d227985 commit 681df27
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions phase/configure_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,13 @@ func (p *ConfigureK0s) configureK0s(h *cluster.Host) error {
return nil
}

func addUnlessExist(slice *[]string, s string) bool {
for _, v := range *slice {
func addUnlessExist(slice []string, s string) bool {
for _, v := range slice {
if v == s {
found = true
return false
}
}
*slice = append(*slice, s)
slice = append(slice, s)

Check failure on line 279 in phase/configure_k0s.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ineffectual assignment to slice (ineffassign)
return true
}

Expand Down Expand Up @@ -313,22 +312,22 @@ func (p *ConfigureK0s) configFor(h *cluster.Host) (string, error) {
case []interface{}:
for _, v := range oldsans {
if s, ok := v.(string); ok {
_ = addUnlessExist(&sans, s)
_ = addUnlessExist(sans, s)
}
}
case []string:
sans = append(sans, oldsans...)
}

if addUnlessExist(&sans, addr) {
if addUnlessExist(sans, addr) {
log.Infof("%s: added %s to spec.api.sans", h, addr)
}

for i, c := range p.Config.Spec.Hosts.Controllers() {
if addUnlessExist(&sans, c.Address()) {
if addUnlessExist(sans, c.Address()) {
log.Infof("%s: added controller %d address %s to spec.api.sans", h, i+1, c.Address())
}
if c.PrivateAddress != "" && addUnlessExist(&sans, c.PrivateAddress) {
if c.PrivateAddress != "" && addUnlessExist(sans, c.PrivateAddress) {
log.Infof("%s: added controller %d private address %s to spec.api.sans", h, i+1, c.PrivateAddress)
}
}
Expand Down

0 comments on commit 681df27

Please sign in to comment.