Skip to content

Commit

Permalink
fixup! Add cluster-schedulable-archs flag
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbernadi committed Jan 10, 2024
1 parent aadeb69 commit 0791f04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
19 changes: 5 additions & 14 deletions cmd/noe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -46,20 +47,10 @@ func Main(ctx context.Context, certDir, preferredArch, schedulableArchs, systemO
schedulableArchSlice = strings.Split(schedulableArchs, ",")
}

if preferredArch != "" && schedulableArchs != "" {
supported := false
for _, schedulableArch := range schedulableArchSlice {
if preferredArch == schedulableArch {
supported = true
break
}
}

if !supported {
err := fmt.Errorf("preferred architecture is not schedulable in the cluster")
log.DefaultLogger.WithError(err).Error("refusing to continue")
os.Exit(1)
}
if preferredArch != "" && schedulableArchs != "" && !slices.Contains(schedulableArchSlice, preferredArch) {
err := fmt.Errorf("preferred architecture is not schedulable in the cluster")
log.DefaultLogger.WithError(err).Error("refusing to continue")
os.Exit(1)
}

// Setup a Manager
Expand Down
9 changes: 2 additions & 7 deletions pkg/arch/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -517,13 +518,7 @@ func (h *Handler) isArchSupported(arch string) bool {
if len(h.schedulableArchitectures) == 0 {
return true
}

for _, schedulableArch := range h.schedulableArchitectures {
if arch == schedulableArch {
return true
}
}
return false
return slices.Contains(h.schedulableArchitectures, arch)
}

// Handler implements admission.DecoderInjector.
Expand Down

0 comments on commit 0791f04

Please sign in to comment.