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

Fix rbac error listing Secrets at cluster scope. #38

Merged
merged 2 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
argov1alpha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/cache"

"os"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -43,9 +45,23 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

// Determine the namespace we're running in. Normally injected into the pod as an env
// var via the Kube downward API configured in the Deployment.
// Developers running the binary locally will need to remember to set the NAMESPACE environment variable.
ns := os.Getenv("NAMESPACE")
if len(ns) == 0 {
setupLog.Info("Please set NAMESPACE environment variable to match where you are running the applicationset controller")
os.Exit(1)
}
setupLog.Info("using argocd namespace", "namespace", ns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe application set is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're destined to be incorporated in argocd it might be best to use the namespace where we expect to land. Although I'm not sure if argocd assumes anything about the namespace it's running in...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're unsure, why don't we remove the concept of a default namespace. If there is no NAMESPACE env var, we error out and ask you to set it, which would only affect developers running the binary locally on their systems. The pod definition will always ensure it's set to whatever the current namespace is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed as a separate commit for your consideration.


mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
// Our cache and thus watches and client queries are restricted to the namespace we're running in. This assumes
// the applicationset controller is in the same namespace as argocd, which should be the same namespace of
// all cluster Secrets and Applications we interact with.
NewCache: cache.MultiNamespacedCacheBuilder([]string{ns}),
HealthProbeBindAddress: probeBindAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
Expand Down
5 changes: 5 additions & 0 deletions manifests/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ spec:
image: registry.cn-hangzhou.aliyuncs.com/appcenter/argocd-applicationset:v0.1.0
imagePullPolicy: Always
name: argocd-applicationset-controller
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
serviceAccountName: argocd-applicationset-controller