diff --git a/pkg/controller/capability.go b/pkg/controller/capability/capability.go similarity index 99% rename from pkg/controller/capability.go rename to pkg/controller/capability/capability.go index fb896aadc..a3934dcef 100644 --- a/pkg/controller/capability.go +++ b/pkg/controller/capability/capability.go @@ -1,4 +1,4 @@ -package controller +package capability import ( "fmt" diff --git a/pkg/controller/capability_test.go b/pkg/controller/capability/capability_test.go similarity index 97% rename from pkg/controller/capability_test.go rename to pkg/controller/capability/capability_test.go index e23d36d55..44071d77f 100644 --- a/pkg/controller/capability_test.go +++ b/pkg/controller/capability/capability_test.go @@ -1,4 +1,4 @@ -package controller +package capability import ( "halkyon.io/operator/pkg/controller/framework" diff --git a/pkg/controller/capability/controller.go b/pkg/controller/capability/controller.go index 47df1e790..d78e7156a 100644 --- a/pkg/controller/capability/controller.go +++ b/pkg/controller/capability/controller.go @@ -2,7 +2,6 @@ package capability import ( "halkyon.io/api/capability/v1beta1" - controller2 "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/runtime" ) @@ -52,11 +51,11 @@ func (r *CapabilityManager) PrimaryResourceType() runtime.Object { } func (r *CapabilityManager) NewFrom(name string, namespace string) (framework.Resource, error) { - return controller2.NewCapability().FetchAndInit(name, namespace, r) + return NewCapability().FetchAndInit(name, namespace, r) } -func asCapability(object runtime.Object) *controller2.Capability { - return object.(*controller2.Capability) +func asCapability(object runtime.Object) *Capability { + return object.(*Capability) } func (r *CapabilityManager) Delete(object framework.Resource) error { diff --git a/pkg/controller/capability/database.go b/pkg/controller/capability/database.go index 7000ea873..a044439b8 100644 --- a/pkg/controller/capability/database.go +++ b/pkg/controller/capability/database.go @@ -1,9 +1,5 @@ package capability -import ( - "halkyon.io/operator/pkg/controller" -) - -func (r *CapabilityManager) installDB(c *controller.Capability) (e error) { +func (r *CapabilityManager) installDB(c *Capability) (e error) { return c.CreateOrUpdate(r.Helper()) } diff --git a/pkg/controller/capability/kubedb_postgres.go b/pkg/controller/capability/kubedb_postgres.go index 4aaed36da..e2f649f67 100644 --- a/pkg/controller/capability/kubedb_postgres.go +++ b/pkg/controller/capability/kubedb_postgres.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/appscode/go/encoding/json/types" kubedbv1 "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" apps "k8s.io/api/apps/v1" core "k8s.io/api/core/v1" @@ -36,12 +35,12 @@ func newOwnedPostgres(owner framework.Resource) postgres { return p } -func (res postgres) ownerAsCapability() *controller.Capability { - return res.Owner().(*controller.Capability) +func (res postgres) ownerAsCapability() *Capability { + return res.Owner().(*Capability) } func (res postgres) Name() string { - return controller.PostgresName(res.Owner()) + return PostgresName(res.Owner()) } //buildSecret returns the postgres resource diff --git a/pkg/controller/capability/names.go b/pkg/controller/capability/names.go new file mode 100644 index 000000000..bcaa741f2 --- /dev/null +++ b/pkg/controller/capability/names.go @@ -0,0 +1,13 @@ +package capability + +import ( + "halkyon.io/operator/pkg/controller/framework" +) + +func PostgresName(owner framework.Resource) string { + return framework.DefaultDependentResourceNameFor(owner) +} + +func ServiceAccountName(owner framework.Resource) string { + return PostgresName(owner) // todo: fix me +} diff --git a/pkg/controller/capability/rolebinding.go b/pkg/controller/capability/rolebinding.go index 925800983..a2053b71f 100644 --- a/pkg/controller/capability/rolebinding.go +++ b/pkg/controller/capability/rolebinding.go @@ -12,7 +12,10 @@ type roleBinding struct { } func newRoleBinding(owner framework.Resource) roleBinding { - rb := controller.NewOwnedRoleBinding(owner, func() string { return "use-scc-privileged" }, func() string { return newRole(owner).Name() }) + rb := controller.NewOwnedRoleBinding(owner, + func() string { return "use-scc-privileged" }, + func() string { return newRole(owner).Name() }, + func() string { return newOwnedPostgres(owner).Name() }) return roleBinding{RoleBinding: rb} } @@ -28,7 +31,7 @@ func (res roleBinding) Build() (runtime.Object, error) { ser := build.(*authorizv1.RoleBinding) owner := res.Owner() - ser.Subjects = append(ser.Subjects, authorizv1.Subject{Kind: "ServiceAccount", Name: controller.PostgresName(owner), Namespace: owner.GetNamespace()}) + ser.Subjects = append(ser.Subjects, authorizv1.Subject{Kind: "ServiceAccount", Name: PostgresName(owner), Namespace: owner.GetNamespace()}) return ser, nil } diff --git a/pkg/controller/capability/secret.go b/pkg/controller/capability/secret.go index 28936dcff..c942d64fc 100644 --- a/pkg/controller/capability/secret.go +++ b/pkg/controller/capability/secret.go @@ -1,7 +1,6 @@ package capability import ( - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,8 +30,8 @@ func newOwnedSecret(owner framework.Resource) secret { return s } -func (res secret) ownerAsCapability() *controller.Capability { - return res.Owner().(*controller.Capability) +func (res secret) ownerAsCapability() *Capability { + return res.Owner().(*Capability) } //buildSecret returns the secret resource diff --git a/pkg/controller/component/build_deployment.go b/pkg/controller/component/build_deployment.go index 5d86b0ad3..528b3786b 100644 --- a/pkg/controller/component/build_deployment.go +++ b/pkg/controller/component/build_deployment.go @@ -2,7 +2,6 @@ package component import ( component "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1" @@ -15,7 +14,7 @@ import ( //createBuildDeployment returns the Deployment config object to be used for deployment using a container image build by Tekton func (res deployment) installBuild() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) // create runtime container using built image (= created by the Tekton build task) runtimeContainer, err := getRuntimeContainerFor(c) @@ -27,7 +26,7 @@ func (res deployment) installBuild() (runtime.Object, error) { // and we will enrich the deployment resource of the runtime container // create a "dev" version of the component to be able to check if the dev deployment exists devDeployment := &appsv1.Deployment{} - _, err = framework.GetHelperFor(c.GetAPIObject()).Fetch(controller.DeploymentNameFor(c, component.DevDeploymentMode), c.Namespace, devDeployment) + _, err = framework.GetHelperFor(c.GetAPIObject()).Fetch(DeploymentNameFor(c, component.DevDeploymentMode), c.Namespace, devDeployment) if err == nil { devContainer := &devDeployment.Spec.Template.Spec.Containers[0] runtimeContainer.Env = devContainer.Env @@ -70,7 +69,7 @@ func (res deployment) installBuild() (runtime.Object, error) { return dep, nil } -func getRuntimeContainerFor(component *controller.Component) (corev1.Container, error) { +func getRuntimeContainerFor(component *Component) (corev1.Container, error) { container := corev1.Container{ Env: populatePodEnvVar(component.Spec), Image: dockerImageURL(component), diff --git a/pkg/controller/component.go b/pkg/controller/component/component.go similarity index 99% rename from pkg/controller/component.go rename to pkg/controller/component/component.go index 2fc3f40fc..ba2b405e7 100644 --- a/pkg/controller/component.go +++ b/pkg/controller/component/component.go @@ -1,4 +1,4 @@ -package controller +package component import ( "context" diff --git a/pkg/controller/component_test.go b/pkg/controller/component/component_test.go similarity index 97% rename from pkg/controller/component_test.go rename to pkg/controller/component/component_test.go index cb47bd2ed..b03a4d303 100644 --- a/pkg/controller/component_test.go +++ b/pkg/controller/component/component_test.go @@ -1,4 +1,4 @@ -package controller +package component import ( "halkyon.io/operator/pkg/controller/framework" diff --git a/pkg/controller/component/controller.go b/pkg/controller/component/controller.go index a16e8e369..b71c23e91 100644 --- a/pkg/controller/component/controller.go +++ b/pkg/controller/component/controller.go @@ -20,7 +20,6 @@ package component import ( "context" component "halkyon.io/api/component/v1beta1" - controller2 "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -63,11 +62,11 @@ func (r *ComponentManager) PrimaryResourceType() runtime.Object { } func (r *ComponentManager) NewFrom(name string, namespace string) (framework.Resource, error) { - return controller2.NewComponent().FetchAndInit(name, namespace, r) + return NewComponent().FetchAndInit(name, namespace, r) } -func (ComponentManager) asComponent(object runtime.Object) *controller2.Component { - return object.(*controller2.Component) +func (ComponentManager) asComponent(object runtime.Object) *Component { + return object.(*Component) } func (r *ComponentManager) CreateOrUpdate(object framework.Resource) (err error) { diff --git a/pkg/controller/component/dependent.go b/pkg/controller/component/dependent.go index 2734c9757..a2135dacc 100644 --- a/pkg/controller/component/dependent.go +++ b/pkg/controller/component/dependent.go @@ -1,7 +1,6 @@ package component import ( - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/runtime" ) @@ -18,10 +17,10 @@ func newBaseDependent(primaryResourceType runtime.Object, owner framework.Resour return base{DependentResourceHelper: framework.NewDependentResource(primaryResourceType, owner)} } -func (res base) ownerAsComponent() *controller.Component { - return res.Owner().(*controller.Component) +func (res base) ownerAsComponent() *Component { + return res.Owner().(*Component) } -func (res base) asComponent(object runtime.Object) *controller.Component { - return object.(*controller.Component) +func (res base) asComponent(object runtime.Object) *Component { + return object.(*Component) } diff --git a/pkg/controller/component/deployment.go b/pkg/controller/component/deployment.go index 0e9333ab9..748984f31 100644 --- a/pkg/controller/component/deployment.go +++ b/pkg/controller/component/deployment.go @@ -2,7 +2,6 @@ package component import ( component "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/runtime" @@ -36,5 +35,5 @@ func (res deployment) Build() (runtime.Object, error) { } func (res deployment) Name() string { - return controller.DeploymentName(res.ownerAsComponent()) + return DeploymentName(res.ownerAsComponent()) } diff --git a/pkg/controller/component/dev_deployment.go b/pkg/controller/component/dev_deployment.go index 27de59e9b..fa6d65b53 100644 --- a/pkg/controller/component/dev_deployment.go +++ b/pkg/controller/component/dev_deployment.go @@ -2,7 +2,6 @@ package component import ( component "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -13,7 +12,7 @@ import ( //buildDevDeployment returns the Deployment config object func (res deployment) installDev() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) // create runtime container runtimeContainer, err := getBaseContainerFor(c.Component) diff --git a/pkg/controller/component/helpers.go b/pkg/controller/component/helpers.go index b4a03ccba..e20b42e4a 100644 --- a/pkg/controller/component/helpers.go +++ b/pkg/controller/component/helpers.go @@ -3,7 +3,6 @@ package component import ( component "halkyon.io/api/component/v1beta1" "halkyon.io/api/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "os" ) @@ -36,7 +35,7 @@ func getEnvAsMap(component component.ComponentSpec) (map[string]string, error) { return tmpEnvVar, nil } -func populateEnvVar(component *controller.Component) { +func populateEnvVar(component *Component) { tmpEnvVar, err := getEnvAsMap(component.Spec) if err != nil { panic(err) @@ -69,7 +68,7 @@ func getBuildLabels(name string) map[string]string { } } -func (r *ComponentManager) PopulateK8sLabels(component *controller.Component, componentType string) map[string]string { +func (r *ComponentManager) PopulateK8sLabels(component *Component, componentType string) map[string]string { labels := map[string]string{} labels[v1beta1.RuntimeLabelKey] = component.Spec.Runtime labels[v1beta1.RuntimeVersionLabelKey] = component.Spec.Version @@ -79,7 +78,7 @@ func (r *ComponentManager) PopulateK8sLabels(component *controller.Component, co return labels } -func baseImage(c *controller.Component) string { +func baseImage(c *Component) string { if c.Spec.BuildConfig.BaseImage != "" { return c.Spec.BuildConfig.BaseImage } else { @@ -93,7 +92,7 @@ func baseImage(c *controller.Component) string { } } -func contextPath(c *controller.Component) string { +func contextPath(c *Component) string { if c.Spec.BuildConfig.ContextPath != "" { return c.Spec.BuildConfig.ContextPath } else { @@ -102,7 +101,7 @@ func contextPath(c *controller.Component) string { } } -func moduleDirName(c *controller.Component) string { +func moduleDirName(c *Component) string { if c.Spec.BuildConfig.ModuleDirName != "" { return c.Spec.BuildConfig.ModuleDirName } else { @@ -111,7 +110,7 @@ func moduleDirName(c *controller.Component) string { } } -func gitRevision(c *controller.Component) string { +func gitRevision(c *Component) string { if c.Spec.BuildConfig.Ref == "" { return "master" } else { @@ -119,7 +118,7 @@ func gitRevision(c *controller.Component) string { } } -func dockerImageURL(c *controller.Component) string { +func dockerImageURL(c *Component) string { // Try to find the registry env var registry, found := os.LookupEnv(RegistryAddressEnvVar) if found { diff --git a/pkg/controller/component/ingress.go b/pkg/controller/component/ingress.go index 8920458ca..c6a81665e 100644 --- a/pkg/controller/component/ingress.go +++ b/pkg/controller/component/ingress.go @@ -1,7 +1,6 @@ package component import ( - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/api/extensions/v1beta1" "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,7 +29,7 @@ func newOwnedIngress(owner framework.Resource) ingress { func (res ingress) Build() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) ingress := &v1beta1.Ingress{ ObjectMeta: v1.ObjectMeta{ Name: res.Name(), diff --git a/pkg/controller/component/mode-build.go b/pkg/controller/component/mode-build.go index 1147298c2..e7247df05 100644 --- a/pkg/controller/component/mode-build.go +++ b/pkg/controller/component/mode-build.go @@ -17,10 +17,6 @@ limitations under the License. package component -import ( - halkyon "halkyon.io/operator/pkg/controller" -) - -func (r *ComponentManager) installBuildMode(component *halkyon.Component, namespace string) (e error) { +func (r *ComponentManager) installBuildMode(component *Component, namespace string) (e error) { return component.CreateOrUpdate(r.Helper()) } diff --git a/pkg/controller/component/mode-dev.go b/pkg/controller/component/mode-dev.go index 0ef2f720d..68e95e561 100644 --- a/pkg/controller/component/mode-dev.go +++ b/pkg/controller/component/mode-dev.go @@ -19,10 +19,9 @@ package component import ( "fmt" - halkyon "halkyon.io/operator/pkg/controller" ) -func (r *ComponentManager) installDevMode(component *halkyon.Component, namespace string) (e error) { +func (r *ComponentManager) installDevMode(component *Component, namespace string) (e error) { component.ObjectMeta.Namespace = namespace // Enrich Component with k8s recommend Labels component.ObjectMeta.Labels = r.PopulateK8sLabels(component, "Backend") diff --git a/pkg/controller/names.go b/pkg/controller/component/names.go similarity index 62% rename from pkg/controller/names.go rename to pkg/controller/component/names.go index 78ee5969c..6959e735f 100644 --- a/pkg/controller/names.go +++ b/pkg/controller/component/names.go @@ -1,16 +1,10 @@ -package controller +package component import ( - "fmt" halkyon "halkyon.io/api/component/v1beta1" "halkyon.io/operator/pkg/controller/framework" - "halkyon.io/operator/pkg/util" ) -func PostgresName(owner framework.Resource) string { - return framework.DefaultDependentResourceNameFor(owner) -} - func DeploymentName(c *Component) string { return DeploymentNameFor(c, c.Spec.DeploymentMode) } @@ -32,14 +26,7 @@ func PVCName(c *Component) string { } func ServiceAccountName(owner framework.Resource) string { - switch owner.(type) { - case *Capability: - return PostgresName(owner) // todo: fix me - case *Component: - return "build-bot" - default: - panic(fmt.Sprintf("a service account shouldn't be created for '%s' %s owner", owner.GetName(), util.GetObjectName(owner))) - } + return "build-bot" } func TaskName(owner framework.Resource) string { diff --git a/pkg/controller/component/pvc.go b/pkg/controller/component/pvc.go index 4a2dee13d..5791909cc 100644 --- a/pkg/controller/component/pvc.go +++ b/pkg/controller/component/pvc.go @@ -2,7 +2,6 @@ package component import ( component "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -31,7 +30,7 @@ func newPvc() pvc { func (res pvc) Build() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) name := res.Name() pvc := &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ @@ -57,7 +56,7 @@ func (res pvc) Build() (runtime.Object, error) { } func (res pvc) Name() string { - return controller.PVCName(res.ownerAsComponent()) + return PVCName(res.ownerAsComponent()) } func getCapacity(c *component.Component) resource.Quantity { diff --git a/pkg/controller/component/rolebinding.go b/pkg/controller/component/rolebinding.go index 3b58a1fa5..89e018908 100644 --- a/pkg/controller/component/rolebinding.go +++ b/pkg/controller/component/rolebinding.go @@ -10,7 +10,10 @@ type roleBinding struct { } func newRoleBinding(owner framework.Resource) roleBinding { - rb := controller.NewOwnedRoleBinding(owner, func() string { return "use-image-scc-privileged" }, func() string { return newRole(owner).Name() }) + rb := controller.NewOwnedRoleBinding(owner, + func() string { return "use-image-scc-privileged" }, + func() string { return newRole(owner).Name() }, + func() string { return ServiceAccountName(owner) }) return roleBinding{RoleBinding: rb} } diff --git a/pkg/controller/component/route.go b/pkg/controller/component/route.go index 9f3e82390..07e88ae04 100644 --- a/pkg/controller/component/route.go +++ b/pkg/controller/component/route.go @@ -2,7 +2,6 @@ package component import ( routev1 "github.com/openshift/api/route/v1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -30,7 +29,7 @@ func newOwnedRoute(owner framework.Resource) route { //buildRoute returns the route resource func (res route) Build() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) route := &routev1.Route{ ObjectMeta: v1.ObjectMeta{ Name: res.Name(), diff --git a/pkg/controller/component/service.go b/pkg/controller/component/service.go index c1d74fcf2..d6d7aad75 100644 --- a/pkg/controller/component/service.go +++ b/pkg/controller/component/service.go @@ -1,7 +1,6 @@ package component import ( - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,7 +29,7 @@ func newOwnedService(owner framework.Resource) service { func (res service) Build() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) ser := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: res.Name(), @@ -58,7 +57,7 @@ func (res service) Build() (runtime.Object, error) { func (res service) Update(toUpdate runtime.Object) (bool, error) { c := res.ownerAsComponent() svc := toUpdate.(*corev1.Service) - name := controller.DeploymentName(c) + name := DeploymentName(c) if svc.Spec.Selector["app"] != name { labels := getAppLabels(name) for key, value := range labels { diff --git a/pkg/controller/component/serviceaccount.go b/pkg/controller/component/serviceaccount.go index 780852199..6e7c19683 100644 --- a/pkg/controller/component/serviceaccount.go +++ b/pkg/controller/component/serviceaccount.go @@ -1,7 +1,6 @@ package component import ( - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/runtime" @@ -31,7 +30,7 @@ func newOwnedServiceAccount(owner framework.Resource) serviceAccount { //buildServiceAccount returns the service resource func (res serviceAccount) Build() (runtime.Object, error) { c := res.ownerAsComponent() - ls := getAppLabels(controller.DeploymentName(c)) + ls := getAppLabels(DeploymentName(c)) sa := &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ Name: res.Name(), @@ -43,5 +42,5 @@ func (res serviceAccount) Build() (runtime.Object, error) { } func (res serviceAccount) Name() string { - return controller.ServiceAccountName(res.Owner()) + return ServiceAccountName(res.Owner()) } diff --git a/pkg/controller/component/taskruns.go b/pkg/controller/component/taskruns.go index 73577dcfe..4e5a1eb8f 100644 --- a/pkg/controller/component/taskruns.go +++ b/pkg/controller/component/taskruns.go @@ -5,7 +5,6 @@ import ( "github.com/knative/pkg/apis" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -42,9 +41,9 @@ func (res taskRun) Build() (runtime.Object, error) { Labels: ls, }, Spec: v1alpha1.TaskRunSpec{ - ServiceAccount: controller.ServiceAccountName(c), + ServiceAccount: ServiceAccountName(c), TaskRef: &v1alpha1.TaskRef{ - Name: controller.TaskName(c), + Name: TaskName(c), }, Inputs: v1alpha1.TaskRunInputs{ Params: []v1alpha1.Param{ diff --git a/pkg/controller/component/tasks.go b/pkg/controller/component/tasks.go index 13821f5aa..e61ed444f 100644 --- a/pkg/controller/component/tasks.go +++ b/pkg/controller/component/tasks.go @@ -2,7 +2,6 @@ package component import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "halkyon.io/operator/pkg/util" corev1 "k8s.io/api/core/v1" @@ -168,5 +167,5 @@ func (res task) Build() (runtime.Object, error) { } func (res task) Name() string { - return controller.TaskName(res.Owner()) + return TaskName(res.Owner()) } diff --git a/pkg/controller/link/component.go b/pkg/controller/link/component.go index c8285bd6a..cb8df3e05 100644 --- a/pkg/controller/link/component.go +++ b/pkg/controller/link/component.go @@ -2,7 +2,6 @@ package link import ( "halkyon.io/api/component/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" "k8s.io/apimachinery/pkg/runtime" ) @@ -44,7 +43,7 @@ func (res component) IsReady(underlying runtime.Object) (ready bool, message str } func (res component) Name() string { - return res.Owner().(*controller.Link).Spec.ComponentName + return res.Owner().(*Link).Spec.ComponentName } func (res component) Build() (runtime.Object, error) { diff --git a/pkg/controller/link/controller.go b/pkg/controller/link/controller.go index 6669d95f6..23f10c74e 100644 --- a/pkg/controller/link/controller.go +++ b/pkg/controller/link/controller.go @@ -5,7 +5,6 @@ import ( "fmt" "halkyon.io/api/component/v1beta1" link "halkyon.io/api/link/v1beta1" - "halkyon.io/operator/pkg/controller" "halkyon.io/operator/pkg/controller/framework" appsv1 "k8s.io/api/apps/v1" "k8s.io/api/core/v1" @@ -36,12 +35,12 @@ func (r *LinkManager) PrimaryResourceType() runtime.Object { return &link.Link{} } -func (LinkManager) asLink(object runtime.Object) *controller.Link { - return object.(*controller.Link) +func (LinkManager) asLink(object runtime.Object) *Link { + return object.(*Link) } func (r *LinkManager) NewFrom(name string, namespace string) (framework.Resource, error) { - return controller.NewLink().FetchAndInit(name, namespace, r) + return NewLink().FetchAndInit(name, namespace, r) } func (r *LinkManager) CreateOrUpdate(object framework.Resource) error { @@ -157,7 +156,7 @@ func (r *LinkManager) fetchDeployment(link *link.Link) (*appsv1.Deployment, erro } } -func (r *LinkManager) updateDeploymentWithLink(d *appsv1.Deployment, link *controller.Link) error { +func (r *LinkManager) updateDeploymentWithLink(d *appsv1.Deployment, link *Link) error { // Update the Deployment of the component if err := r.update(d); err != nil { r.Helper().ReqLogger.Info("Failed to update deployment.") diff --git a/pkg/controller/link.go b/pkg/controller/link/link.go similarity index 99% rename from pkg/controller/link.go rename to pkg/controller/link/link.go index a661e326c..4aa2ab74b 100644 --- a/pkg/controller/link.go +++ b/pkg/controller/link/link.go @@ -1,4 +1,4 @@ -package controller +package link import ( halkyon "halkyon.io/api/link/v1beta1" diff --git a/pkg/controller/rolebinding.go b/pkg/controller/rolebinding.go index 216855d63..8e4c40a72 100644 --- a/pkg/controller/rolebinding.go +++ b/pkg/controller/rolebinding.go @@ -11,6 +11,7 @@ type RoleBinding struct { *framework.DependentResourceHelper namer func() string associatedRoleNamer func() string + serviceAccountNamer func() string } func (res RoleBinding) Update(toUpdate runtime.Object) (bool, error) { @@ -20,7 +21,7 @@ func (res RoleBinding) Update(toUpdate runtime.Object) (bool, error) { // check if the binding contains the current owner as subject namespace := owner.GetNamespace() - name := ServiceAccountName(owner) + name := res.serviceAccountNamer() found := false for _, subject := range rb.Subjects { if subject.Name == name && subject.Namespace == namespace { @@ -41,15 +42,16 @@ func (res RoleBinding) Update(toUpdate runtime.Object) (bool, error) { } func (res RoleBinding) NewInstanceWith(owner framework.Resource) framework.DependentResource { - return NewOwnedRoleBinding(owner, res.namer, res.associatedRoleNamer) + return NewOwnedRoleBinding(owner, res.namer, res.associatedRoleNamer, res.serviceAccountNamer) } -func NewOwnedRoleBinding(owner framework.Resource, namer, associatedRoleNamer func() string) RoleBinding { +func NewOwnedRoleBinding(owner framework.Resource, namer, associatedRoleNamer, serviceAccountNamer func() string) RoleBinding { dependent := framework.NewDependentResource(&authorizv1.RoleBinding{}, owner) rolebinding := RoleBinding{ DependentResourceHelper: dependent, namer: namer, associatedRoleNamer: associatedRoleNamer, + serviceAccountNamer: serviceAccountNamer, } dependent.SetDelegate(rolebinding) return rolebinding @@ -72,7 +74,7 @@ func (res RoleBinding) Build() (runtime.Object, error) { Name: res.associatedRoleNamer(), }, Subjects: []authorizv1.Subject{ - {Kind: "ServiceAccount", Name: ServiceAccountName(c), Namespace: namespace}, + {Kind: "ServiceAccount", Name: res.serviceAccountNamer(), Namespace: namespace}, }, } return ser, nil