Skip to content

Commit

Permalink
move MakeServiceAccount to pkg/reconciler/resources
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Jun 10, 2020
1 parent db56628 commit 3d8803b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pkg/reconciler/pingsource/pingsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
listers "knative.dev/eventing/pkg/client/listers/sources/v1alpha2"
"knative.dev/eventing/pkg/logging"
"knative.dev/eventing/pkg/reconciler/pingsource/resources"
recresources "knative.dev/eventing/pkg/reconciler/resources"
"knative.dev/eventing/pkg/utils"
)

Expand Down Expand Up @@ -201,7 +202,7 @@ func (r *Reconciler) reconcileServiceAccount(ctx context.Context, source *v1alph
sa, err := r.serviceAccountLister.ServiceAccounts(source.Namespace).Get(saName)
if err != nil {
if apierrors.IsNotFound(err) {
expected := resources.MakeServiceAccount(source, saName)
expected := recresources.MakeServiceAccount(source, saName)
sa, err := r.kubeClientSet.CoreV1().ServiceAccounts(source.Namespace).Create(expected)
if err != nil {
return sa, newServiceAccountWarn(err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/pingsource/pingsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake"
"knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource"
"knative.dev/eventing/pkg/reconciler/pingsource/resources"
recresources "knative.dev/eventing/pkg/reconciler/resources"
"knative.dev/eventing/pkg/utils"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand Down Expand Up @@ -646,7 +647,7 @@ func makeAvailableMTAdapter() *appsv1.Deployment {
func MakeServiceAccount(sourceName, sourceUID string) *corev1.ServiceAccount {
source := NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2UID(sourceUID))
return resources.MakeServiceAccount(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID)))
return recresources.MakeServiceAccount(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID)))
}

func MakeRoleBinding(sourceName, sourceUID string) *rbacv1.RoleBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/kmeta"

"knative.dev/eventing/pkg/apis/sources/v1alpha2"
)

// MakeServiceAccount creates a ServiceAccount object for the given PingSource
func MakeServiceAccount(source *v1alpha2.PingSource, name string) *corev1.ServiceAccount {
// MakeServiceAccount creates a ServiceAccount object for the given referable object
func MakeServiceAccount(obj kmeta.OwnerRefable, name string) *corev1.ServiceAccount {
return &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: source.Namespace,
Namespace: obj.GetObjectMeta().GetNamespace(),
Name: name,
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(source),
*kmeta.NewControllerRef(obj),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ import (
func TestNewServiceAccount(t *testing.T) {
testNS := "test-ns"
testName := "test-name"
src := &v1alpha2.PingSource{
obj := &v1alpha2.PingSource{
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNS,
UID: "source-uid",
},
Spec: v1alpha2.PingSourceSpec{
Schedule: "*/2 * * * *",
JsonData: "data",
},
}

Expand All @@ -47,12 +42,12 @@ func TestNewServiceAccount(t *testing.T) {
Namespace: testNS,
Name: testName,
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(src),
*kmeta.NewControllerRef(obj),
},
},
}

got := MakeServiceAccount(src, testName)
got := MakeServiceAccount(obj, testName)

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("unexpected condition (-want, +got) = %v", diff)
Expand Down

0 comments on commit 3d8803b

Please sign in to comment.