Skip to content
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

allow default system namespace to be overridden using an env var #427

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ kubectl create clusterrolebinding cluster-admin-binding \
--user="${USER}"
```

### Install in custom namespace
Copy link
Collaborator

Choose a reason for hiding this comment

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

i have one completely minor piece of feedback: usually we have an extra newline after a header.

i'm also happy to lgtm and let @mattmoor-sockpuppet fix that tho XD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool - thanks, I just added the extra newline anyways.

1. To install into a different namespace you will need to modify resources in the `./config` folder
- remove all `namespace: tekton` references from all yaml files
- delete the `namespace.yaml` [here](https://github.com/knative/build-pipeline/blob/c1500fab83b09edadefb38bb8920a0c837d8f32b/config/100-namespace.yaml)
- modify the `subjects.namespace` [here](https://github.com/knative/build-pipeline/blob/c1500fab83b09edadefb38bb8920a0c837d8f32b/config/201-clusterrolebinding.yaml#L21) value to the desired namespace
- add `downwardapi` entry to webhook and controller `deployment` resources. E.g. add the environment variable section from the code snippet below to [controller](https://github.com/knative/build-pipeline/blob/c1500fab83b09edadefb38bb8920a0c837d8f32b/config/controller.yaml#L29) and [webhook](https://github.com/knative/build-pipeline/blob/c1500fab83b09edadefb38bb8920a0c837d8f32b/config/webhook.yaml#L32)
```yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove the additional space in yaml example. Markdown render looks bit weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

env:
- name: SYSTEM_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
```

## Iterating

While iterating on the project, you may need to:
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {
logger.Fatalf("Error building pipeline clientset: %v", err)
}

configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace)
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.GetNamespace())

opt := reconciler.Options{
KubeClientSet: kubeClient,
Expand Down
4 changes: 2 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
logger.Fatal("Failed to get the client set", zap.Error(err))
}
// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace)
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.GetNamespace())
configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logging.WebhookLogKey))
if err = configMapWatcher.Start(stopCh); err != nil {
logger.Fatalf("failed to start configuration manager: %v", err)
Expand All @@ -73,7 +73,7 @@ func main() {
options := webhook.ControllerOptions{
ServiceName: "tekton-pipelines-webhook",
DeploymentName: "tekton-pipelines-webhook",
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Port: 443,
SecretName: "webhook-certs",
WebhookName: "webhook.tekton.dev",
Expand Down
18 changes: 9 additions & 9 deletions pkg/artifacts/artifact_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
desc: "valid bucket",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
desc: "location empty",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand All @@ -91,7 +91,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
desc: "missing location",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand All @@ -113,7 +113,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
desc: "no config map data",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
},
Expand All @@ -131,7 +131,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
desc: "no secret",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
desc: "valid bucket",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand All @@ -221,7 +221,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
desc: "location empty",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand All @@ -235,7 +235,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
desc: "missing location",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
Data: map[string]string{
Expand All @@ -248,7 +248,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
desc: "no config map data",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: v1alpha1.BucketConfigName,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/artifacts/artifacts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ArtifactStorageInterface interface {
// InitializeArtifactStorage will check if there is there is a
// bucket configured or create a PVC
func InitializeArtifactStorage(pr *v1alpha1.PipelineRun, c kubernetes.Interface, logger *zap.SugaredLogger) (ArtifactStorageInterface, error) {
configMap, err := c.CoreV1().ConfigMaps(system.Namespace).Get(v1alpha1.BucketConfigName, metav1.GetOptions{})
configMap, err := c.CoreV1().ConfigMaps(system.GetNamespace()).Get(v1alpha1.BucketConfigName, metav1.GetOptions{})
shouldCreatePVC, err := needsPVC(configMap, err, logger)
if err != nil {
return nil, err
Expand Down Expand Up @@ -87,7 +87,7 @@ func needsPVC(configMap *corev1.ConfigMap, err error, logger *zap.SugaredLogger)
// GetArtifactStorage returns the storage interface to enable
// consumer code to get a container step for copy to/from storage
func GetArtifactStorage(prName string, c kubernetes.Interface, logger *zap.SugaredLogger) (ArtifactStorageInterface, error) {
configMap, err := c.CoreV1().ConfigMaps(system.Namespace).Get(v1alpha1.BucketConfigName, metav1.GetOptions{})
configMap, err := c.CoreV1().ConfigMaps(system.GetNamespace()).Get(v1alpha1.BucketConfigName, metav1.GetOptions{})
pvc, err := needsPVC(configMap, err, logger)
if err != nil {
return nil, err
Expand Down
17 changes: 0 additions & 17 deletions pkg/names.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func getRunName(pr *v1alpha1.PipelineRun) string {
func getPipelineRunController(d test.Data, recorder record.EventRecorder) test.TestAssets {
c, i := test.SeedTestData(d)
observer, logs := observer.New(zap.InfoLevel)
configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.Namespace)
configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.GetNamespace())
return test.TestAssets{
Controller: NewController(
reconciler.Options{
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/v1alpha1/taskrun/config/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestEntrypointConfiguration(t *testing.T) {
},
config: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: EntrypointConfigName,
},
Data: map[string]string{
Expand All @@ -53,7 +53,7 @@ func TestEntrypointConfiguration(t *testing.T) {
},
config: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: EntrypointConfigName,
},
Data: map[string]string{},
Expand All @@ -65,7 +65,7 @@ func TestEntrypointConfiguration(t *testing.T) {
},
config: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace,
Namespace: system.GetNamespace(),
Name: EntrypointConfigName,
},
}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/v1alpha1/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func getRunName(tr *v1alpha1.TaskRun) string {
func getTaskRunController(d test.Data) test.TestAssets {
c, i := test.SeedTestData(d)
observer, logs := observer.New(zap.InfoLevel)
configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.Namespace)
configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.GetNamespace())
return test.TestAssets{
Controller: NewController(
reconciler.Options{
Expand Down
18 changes: 14 additions & 4 deletions pkg/system/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ limitations under the License.

package system

import "os"

const (
// Namespace holds the K8s namespace where our build-pipeline system
// components run.
Namespace = "tekton-pipelines"
PipelineKind = "Pipeline"
DefaultNamespace = "tekton-pipelines"
SystemNamespaceEnvVar = "SYSTEM_NAMESPACE"
)

// GetNamespace holds the K8s namespace where our build-pipeline system
// components run.
func GetNamespace() string {
systemNamespace := os.Getenv(SystemNamespaceEnvVar)
if systemNamespace == "" {
return DefaultNamespace
}
return os.Getenv(SystemNamespaceEnvVar)
}