Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #880 from sohankunkerkar/federation-namespace
Browse files Browse the repository at this point in the history
Set kubefed-namespace via the config mechanism for in-cluster deployment
  • Loading branch information
k8s-ci-robot authored Jul 18, 2019
2 parents 16493d5 + c6c6329 commit 7062938
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ spec:
runAsUser: 1001
serviceAccountName: kubefed-controller
containers:
- args:
- --kubefed-namespace=$(KUBEFED_NAMESPACE)
command:
- command:
- /hyperfed/controller-manager
image: "{{ .Values.repository }}/{{ .Values.image }}:{{ .Values.tag }}"
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
Expand All @@ -38,11 +36,6 @@ spec:
{{- if .Values.resources }}
{{ toYaml .Values.resources | indent 12 }}
{{- end }}
env:
- name: KUBEFED_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
terminationGracePeriodSeconds: 10
---
apiVersion: apps/v1
Expand Down
18 changes: 18 additions & 0 deletions cmd/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -107,6 +109,22 @@ func Run(opts *options.Options, stopChan <-chan struct{}) error {
panic(err)
}

runningInCluster := len(masterURL) == 0 && len(kubeconfig) == 0
if runningInCluster && len(opts.Config.KubeFedNamespace) == 0 {
// For in-cluster deployment set the namespace associated
// with the service account token
data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
if err != nil {
klog.Fatalf("An error occurred while attempting to discover the KubeFed namespace from the service account: %v", err)
}
opts.Config.KubeFedNamespace = strings.TrimSpace(string(data))
}

// Validate if a kubefed-namespace is configured
if len(opts.Config.KubeFedNamespace) == 0 {
klog.Fatalf("The KubeFed namespace must be specified via --kubefed-namespace")
}

setOptionsByKubeFedConfig(opts)

if err := utilfeature.DefaultFeatureGate.SetFromMap(opts.FeatureGates); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Options struct {

// AddFlags adds flags to fs and binds them to options.
func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.Config.KubeFedNamespace, "kubefed-namespace", util.DefaultKubeFedSystemNamespace, "The namespace the KubeFed control plane is deployed in.")
fs.StringVar(&o.Config.KubeFedNamespace, "kubefed-namespace", "", "The namespace the KubeFed control plane is deployed in.")
}

func NewOptions() *Options {
Expand Down

0 comments on commit 7062938

Please sign in to comment.