-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use roles from the embedded-cluster config #4133
Merged
laverya
merged 20 commits into
main
from
laverya/sc-92433/in-the-admin-console-show-the-name-for-the
Nov 16, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7020000
parse the embedded-cluster installations to get roles
laverya f125282
undo unintentional go mod change
laverya 823be1a
increase the go version again
laverya 2bc6f70
update trivy and scanning go version
laverya dfb2622
go version again
laverya f036c50
use the same setup-go version as the rest of the repo
laverya fae4f77
display roles in UI
laverya 84dab6d
use renamed controller role names properly
laverya 10ab562
sort node roles before creating the node join command
laverya e4fd320
Merge remote-tracking branch 'origin/main' into laverya/sc-92433/in-t…
laverya ec625f8
add test for new route
laverya 588260e
empty commit for CI
laverya 302e5e6
apply node role labels
laverya c913f06
log k0s join command for debugging
laverya 86160f5
Merge remote-tracking branch 'origin/main' into laverya/sc-92433/in-t…
laverya b12e823
okteto go versions
laverya 55eb11b
keep the k0s node join command log
laverya ae1d078
ensure label keys/values are legal
laverya 83cb62a
Merge remote-tracking branch 'origin/main' into laverya/sc-92433/in-t…
laverya f29dac9
update go everywhere
laverya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20 as builder | ||
FROM golang:1.21 as builder | ||
WORKDIR /action | ||
COPY . /action | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# syntax=docker/dockerfile:1.3 | ||
FROM golang:1.20.5 | ||
FROM golang:1.21.3 | ||
|
||
EXPOSE 2345 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.20 as deps | ||
FROM golang:1.21 as deps | ||
|
||
RUN go install github.com/go-delve/delve/cmd/[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/replicatedhq/kots/kurl_proxy | ||
|
||
go 1.20 | ||
go 1.21.3 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.9.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package embeddedcluster | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
||
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-operator/api/v1beta1" | ||
) | ||
|
||
const DEFAULT_CONTROLLER_ROLE_NAME = "controller" | ||
|
||
var labelValueRegex = regexp.MustCompile(`[^a-zA-Z0-9-_.]+`) | ||
|
||
// GetRoles will get a list of role names | ||
func GetRoles(ctx context.Context) ([]string, error) { | ||
config, err := ClusterConfig(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get cluster config: %w", err) | ||
} | ||
|
||
if config == nil { | ||
// use the default nil spec | ||
config = &embeddedclusterv1beta1.ConfigSpec{} | ||
} | ||
|
||
// determine role names | ||
roles := []string{} | ||
if config.Controller.Name != "" { | ||
roles = append(roles, config.Controller.Name) | ||
} else { | ||
roles = append(roles, DEFAULT_CONTROLLER_ROLE_NAME) | ||
} | ||
|
||
for _, role := range config.Custom { | ||
if role.Name != "" { | ||
roles = append(roles, role.Name) | ||
} | ||
} | ||
|
||
return roles, nil | ||
} | ||
|
||
// ControllerRoleName determines the name for the 'controller' role | ||
// this might be part of the config, or it might be the default | ||
func ControllerRoleName(ctx context.Context) (string, error) { | ||
conf, err := ClusterConfig(ctx) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get cluster config: %w", err) | ||
} | ||
|
||
if conf != nil && conf.Controller.Name != "" { | ||
return conf.Controller.Name, nil | ||
} | ||
return DEFAULT_CONTROLLER_ROLE_NAME, nil | ||
} | ||
|
||
// sort roles by name, but put controller first | ||
func SortRoles(controllerRole string, inputRoles []string) []string { | ||
roles := inputRoles | ||
|
||
// determine if the controller role is present | ||
hasController := false | ||
controllerIdx := 0 | ||
for idx, role := range roles { | ||
if role == controllerRole { | ||
hasController = true | ||
controllerIdx = idx | ||
break | ||
} | ||
} | ||
|
||
// if the controller role is present, remove it | ||
if hasController { | ||
roles = append(roles[:controllerIdx], roles[controllerIdx+1:]...) | ||
} | ||
|
||
// sort the roles | ||
sort.Strings(roles) | ||
|
||
// if the controller role was present, add it back to the front | ||
if hasController { | ||
roles = append([]string{controllerRole}, roles...) | ||
} | ||
|
||
return roles | ||
} | ||
|
||
// getRoleNodeLabels looks up roles in the cluster config and determines the additional labels to be applied from that | ||
func getRoleNodeLabels(ctx context.Context, roles []string) ([]string, error) { | ||
config, err := ClusterConfig(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get cluster config: %w", err) | ||
} | ||
|
||
return getRoleLabelsImpl(config, roles), nil | ||
} | ||
|
||
func labelify(s string) string { | ||
// remove illegal characters | ||
removechars := labelValueRegex.ReplaceAllString(s, "-") | ||
// remove leading dashes | ||
trimmed := strings.TrimPrefix(removechars, "-") | ||
// restrict it to 63 characters | ||
if len(trimmed) > 63 { | ||
trimmed = trimmed[:63] | ||
} | ||
// remove trailing dashes | ||
trimmed = strings.TrimSuffix(trimmed, "-") | ||
return trimmed | ||
} | ||
|
||
func getRoleLabelsImpl(config *embeddedclusterv1beta1.ConfigSpec, roles []string) []string { | ||
toReturn := []string{} | ||
|
||
if config == nil { | ||
return toReturn | ||
} | ||
|
||
for _, role := range roles { | ||
if role == config.Controller.Name { | ||
for k, v := range config.Controller.Labels { | ||
toReturn = append(toReturn, fmt.Sprintf("%s=%s", labelify(k), labelify(v))) | ||
} | ||
} | ||
for _, customRole := range config.Custom { | ||
if role == customRole.Name { | ||
for k, v := range customRole.Labels { | ||
toReturn = append(toReturn, fmt.Sprintf("%s=%s", labelify(k), labelify(v))) | ||
} | ||
} | ||
} | ||
} | ||
|
||
sort.Strings(toReturn) | ||
|
||
return toReturn | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears to be required as part of importing embedded-cluster-operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make it an easier import if there was a separate module for the kinds/apis as we have for kotskinds and kurlkinds? probably not necessary now, but thinking ahead for when the project inevitably grows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be something to consider certainly