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

Commit

Permalink
syntax error, comma
Browse files Browse the repository at this point in the history
  • Loading branch information
s1cyan committed Jun 12, 2020
1 parent 17fe36a commit 27adb56
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions pkg/controller/kabaneroplatform/targetnamespaces.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
package kabaneroplatform

import (
"context"
"errors"
"fmt"
"strings"

kabanerov1alpha2 "github.com/kabanero-io/kabanero-operator/pkg/apis/kabanero/v1alpha2"

"github.com/go-logr/logr"

rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type targetNamespaceRoleBindingTemplate struct {
name string
saName string
saNamespace string
name string
saName string
saNamespace string
clusterRoleName string
}

func (info targetNamespaceRoleBindingTemplate) generate(targetNamespace string) rbacv1.RoleBinding {
return rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: info.name,
Name: info.name,
Namespace: targetNamespace,
},
Subjects: []rbacv1.Subject{
rbacv1.Subject{
Kind: "ServiceAccount",
Name: info.saName,
Kind: "ServiceAccount",
Name: info.saName,
Namespace: info.saNamespace,
},
},
RoleRef: rbacv1.RoleRef{
Kind: "ClusterRole",
Name: info.clusterRoleName,
Kind: "ClusterRole",
Name: info.clusterRoleName,
APIGroup: "rbac.authorization.k8s.io",
},
}
Expand All @@ -50,7 +51,7 @@ func (info targetNamespaceRoleBindingTemplate) generate(targetNamespace string)
// namespaces from the Kabanero CR instance.
func getTargetNamespaces(targetNamespaces []string, defaultNamespace string) []string {
targetnamespaceList := targetNamespaces

// If targetNamespaces is empty, default to binding to kabanero
if len(targetnamespaceList) == 0 {
targetnamespaceList = append(targetnamespaceList, defaultNamespace)
Expand All @@ -60,20 +61,20 @@ func getTargetNamespaces(targetNamespaces []string, defaultNamespace string) []s
}

// Create the binding templates
func createBindingTemplates(saNamespace string) []targetNamespaceRoleBindingTemplate{
return []targetNamespaceRoleBindingTemplate {
func createBindingTemplates(saNamespace string) []targetNamespaceRoleBindingTemplate {
return []targetNamespaceRoleBindingTemplate{
{
name: "kabanero-pipeline-deploy-rolebinding",
saName: "kabanero-pipeline",
saNamespace: saNamespace,
name: "kabanero-pipeline-deploy-rolebinding",
saName: "kabanero-pipeline",
saNamespace: saNamespace,
clusterRoleName: "kabanero-pipeline-deploy-role",
},
// TODO: Second role binding for CLI service
{
name: "kabanero-cli-deploy-rolebinding"
saName: "kabanero-cli"
saNamespace: saNamespace,
clusterRoleName: "kabanero-cli-service-deployments-role"
name: "kabanero-cli-deploy-rolebinding",
saName: "kabanero-cli",
saNamespace: saNamespace,
clusterRoleName: "kabanero-cli-service-deployments-role",
},
}
}
Expand Down Expand Up @@ -113,7 +114,7 @@ func reconcileTargetNamespaces(ctx context.Context, k *kabanerov1alpha2.Kabanero
// TODO: did I do this right? need to process the namespaces, then look at errorNamespaces and
// generate an error message for namespaces that did not exist. Once we have a watch set
// up, that should take care of partially active lists, and the delete case.

// Compute the new, deleted, and common namespace names
statusTargetNamespaces := sets.NewString(getTargetNamespaces(k.Status.TargetNamespaces.Namespaces, k.GetNamespace())...)
oldNamespaces := statusTargetNamespaces.Difference(specTargetNamespaces)
Expand All @@ -122,7 +123,7 @@ func reconcileTargetNamespaces(ctx context.Context, k *kabanerov1alpha2.Kabanero

// Create the templates
bindingTemplates := createBindingTemplates(k.GetNamespace())

// For removed namespaces, delete the role bindings
for namespace, _ := range oldNamespaces {
for _, bindingTemplate := range bindingTemplates {
Expand Down Expand Up @@ -191,7 +192,7 @@ func namespaceExists(ctx context.Context, inNamespace string, cl client.Client)
Kind: "Namespace",
Version: "v1",
})
err := cl.Get(ctx, client.ObjectKey{Namespace: inNamespace, Name: inNamespace,}, namespace)
err := cl.Get(ctx, client.ObjectKey{Namespace: inNamespace, Name: inNamespace}, namespace)
if err == nil {
return true, nil
}
Expand Down

0 comments on commit 27adb56

Please sign in to comment.