Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
Functions, not variables
Browse files Browse the repository at this point in the history
  • Loading branch information
liztio committed Jul 15, 2019
1 parent 0a418a5 commit 550cd63
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 83 deletions.
9 changes: 6 additions & 3 deletions objects/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package objects
import "k8s.io/apimachinery/pkg/runtime"

func GetAll(capdImage string) []runtime.Object {
namespaceObj := GetNamespace()
statefulSet := GetStatefulSet(capdImage)
clusterRole := GetClusterRole()
clusterRoleBinding := GetClusterRoleBinding()

return []runtime.Object{
&Namespace,
&namespaceObj,
&statefulSet,
&ClusterRole,
&ClusterRoleBinding,
&clusterRole,
&clusterRoleBinding,
}
}
12 changes: 7 additions & 5 deletions objects/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (

const namespace = "docker-provider-system"

var Namespace = core.Namespace{
ObjectMeta: meta.ObjectMeta{
Labels: map[string]string{"controller-tools.k8s.io": "1.0"},
Name: namespace,
},
func GetNamespace() core.Namespace {
return core.Namespace{
ObjectMeta: meta.ObjectMeta{
Labels: map[string]string{"controller-tools.k8s.io": "1.0"},
Name: namespace,
},
}
}

var (
Expand Down
156 changes: 81 additions & 75 deletions objects/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,92 @@ import (
capi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

var ClusterRole = rbac.ClusterRole{
ObjectMeta: meta.ObjectMeta{
Name: "docker-provider-manager-role",
},
Rules: []rbac.PolicyRule{
{
APIGroups: []string{
capi.SchemeGroupVersion.Group,
},
Resources: []string{
"clusters",
"clusters/status",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
{
APIGroups: []string{
capi.SchemeGroupVersion.Group,
},
Resources: []string{
"machines",
"machines/status",
"machinedeployments",
"machinedeployments/status",
"machinesets",
"machinesets/status",
"machineclasses",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
const clusterRoleName = "docker-provider-manager-role"

func GetClusterRole() rbac.ClusterRole {
return rbac.ClusterRole{
ObjectMeta: meta.ObjectMeta{
Name: clusterRoleName,
},
{
APIGroups: []string{
core.GroupName,
Rules: []rbac.PolicyRule{
{
APIGroups: []string{
capi.SchemeGroupVersion.Group,
},
Resources: []string{
"clusters",
"clusters/status",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
Resources: []string{
"nodes",
"events",
"secrets",
{
APIGroups: []string{
capi.SchemeGroupVersion.Group,
},
Resources: []string{
"machines",
"machines/status",
"machinedeployments",
"machinedeployments/status",
"machinesets",
"machinesets/status",
"machineclasses",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
{
APIGroups: []string{
core.GroupName,
},
Resources: []string{
"nodes",
"events",
"secrets",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
},
},
}
}

var ClusterRoleBinding = rbac.ClusterRoleBinding{
ObjectMeta: meta.ObjectMeta{
Name: "docker-provider-manager-rolebinding",
},
RoleRef: rbac.RoleRef{
Kind: "ClusterRole",
Name: ClusterRole.ObjectMeta.Name,
APIGroup: rbac.GroupName,
},
Subjects: []rbac.Subject{{
Kind: rbac.ServiceAccountKind,
Name: "default",
Namespace: namespace,
}},
func GetClusterRoleBinding() rbac.ClusterRoleBinding {
return rbac.ClusterRoleBinding{
ObjectMeta: meta.ObjectMeta{
Name: "docker-provider-manager-rolebinding",
},
RoleRef: rbac.RoleRef{
Kind: "ClusterRole",
Name: clusterRoleName,
APIGroup: rbac.GroupName,
},
Subjects: []rbac.Subject{{
Kind: rbac.ServiceAccountKind,
Name: "default",
Namespace: namespace,
}},
}
}

0 comments on commit 550cd63

Please sign in to comment.