Skip to content

Commit

Permalink
Handle CNI usage of token refresher as well
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport committed Jul 6, 2022
1 parent 79d7243 commit d07d05d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions calico/_includes/charts/calico/templates/calico-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ spec:
name: kubernetes-services-endpoint
optional: true
env:
{{- if eq .Values.network "flannel" }}
# Set the serviceaccount name to use for the Calico CNI plugin.
# We use canal-node instead of calico-node when using flannel networking.
- name: CALICO_CNI_SERVICE_ACCOUNT
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
{{- end }}
{{- if .Values.bpf }}
# Overrides for kubernetes API server host/port. Needed in BPF mode.
- name: KUBERNETES_SERVICE_HOST
Expand Down
2 changes: 1 addition & 1 deletion cni-plugin/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ current-context: calico-context`
if err != nil {
logrus.WithError(err).Fatal("Unable to create client for generating CNI token")
}
tr := cni.NewTokenRefresher(clientset, cni.NamespaceOfUsedServiceAccount(), cni.DefaultServiceAccountName)
tr := cni.NewTokenRefresher(clientset, cni.NamespaceOfUsedServiceAccount(), cni.CNIServiceAccountName())
tu, err := tr.UpdateToken()
if err != nil {
logrus.WithError(err).Fatal("Unable to create token for CNI kubeconfig")
Expand Down
6 changes: 3 additions & 3 deletions node/pkg/cni/token_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func Run() {
if err != nil {
logrus.WithError(err).Fatal("Failed to create in cluster client set")
}
tr := NewTokenRefresher(clientset, NamespaceOfUsedServiceAccount(), cniServiceAccountName())
tr := NewTokenRefresher(clientset, NamespaceOfUsedServiceAccount(), CNIServiceAccountName())
tokenChan := tr.TokenChan()
go tr.Run()

Expand All @@ -237,9 +237,9 @@ func Run() {
}
}

// cniServiceAccountName returns the name of the serviceaccount to use for the CNI plugin token request.
// CNIServiceAccountName returns the name of the serviceaccount to use for the CNI plugin token request.
// This can be set via the CALICO_CNI_SERVICE_ACCOUNT environment variable, and defaults to "calico-node" otherwise.
func cniServiceAccountName() string {
func CNIServiceAccountName() string {
if sa := os.Getenv("CALICO_CNI_SERVICE_ACCOUNT"); sa != "" {
logrus.WithField("name", sa).Debug("Using service account from CALICO_CNI_SERVICE_ACCOUNT")
return sa
Expand Down

0 comments on commit d07d05d

Please sign in to comment.