Skip to content

Commit

Permalink
Add ability to ignore labels from registering clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Sep 3, 2020
1 parent dab05a2 commit 22eb1a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions charts/fleet/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data:
"agentImagePullPolicy": "{{ .Values.agentImage.imagePullPolicy }}",
"apiServerURL": "{{.Values.apiServerURL}}",
"apiServerCA": "{{b64enc .Values.apiServerCA}}",
"ignoreClusterRegistrationLabels": {{.Values.ignoreClusterRegistrationLabels}},
"bootstrap": {
"dirs": "{{.Values.bootstrap.dirs}}",
"repo": "{{.Values.bootstrap.repo}}",
Expand Down
3 changes: 3 additions & 0 deletions charts/fleet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ webhookReceiverURL: ""
# webhook will be setup if webhookReceiverURL is also set
githubURLPrefix: https://github.com

# Whether you want to allow cluster upon registration to specify their labels.
ignoreClusterRegistrationLabels: false

bootstrap:
# The namespace that will be autocreated and the local cluster will be registered in
namespace: fleet-local
Expand Down
21 changes: 11 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ var (
)

type Config struct {
AgentImage string `json:"agentImage,omitempty"`
AgentImagePullPolicy string `json:"agentImagePullPolicy,omitempty"`
ManageAgent *bool `json:"manageAgent,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ClientID string `json:"clientID,omitempty"`
APIServerURL string `json:"apiServerURL,omitempty"`
APIServerCA []byte `json:"apiServerCA,omitempty"`
Bootstrap Bootstrap `json:"bootstrap,omitempty"`
GithubURLPrefix string `json:"githubURLPrefix,omitempty"`
WebhookReceiverURL string `json:"webhookReceiverURL,omitempty"`
AgentImage string `json:"agentImage,omitempty"`
AgentImagePullPolicy string `json:"agentImagePullPolicy,omitempty"`
ManageAgent *bool `json:"manageAgent,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
ClientID string `json:"clientID,omitempty"`
APIServerURL string `json:"apiServerURL,omitempty"`
APIServerCA []byte `json:"apiServerCA,omitempty"`
Bootstrap Bootstrap `json:"bootstrap,omitempty"`
GithubURLPrefix string `json:"githubURLPrefix,omitempty"`
WebhookReceiverURL string `json:"webhookReceiverURL,omitempty"`
IgnoreClusterRegistrationLabels bool `json:"ignoreClusterRegistrationLabels,omitempty"`
}

type Bootstrap struct {
Expand Down
7 changes: 5 additions & 2 deletions pkg/controllers/clusterregistration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

fleetgroup "github.com/rancher/fleet/pkg/apis/fleet.cattle.io"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
"github.com/rancher/fleet/pkg/config"
fleetcontrollers "github.com/rancher/fleet/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/wrangler/pkg/apply"
corecontrollers "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
Expand Down Expand Up @@ -312,8 +313,10 @@ func (h *handler) createOrGetCluster(request *fleet.ClusterRegistration) (*fleet
}

labels := map[string]string{}
for k, v := range request.Spec.ClusterLabels {
labels[k] = v
if !config.Get().IgnoreClusterRegistrationLabels {
for k, v := range request.Spec.ClusterLabels {
labels[k] = v
}
}
labels[fleet.ClusterAnnotation] = clusterName

Expand Down

0 comments on commit 22eb1a9

Please sign in to comment.