Skip to content

Commit 91bbe74

Browse files
committed
Refactor pkg structure
- move pkg/test to internal/testutil - move pkg/update to internal/update Signed-off-by: Stefan Prodan <[email protected]>
1 parent 9b8f0a6 commit 91bbe74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+161
-112
lines changed

internal/controller/controllers_fuzzer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import (
5858
sourcev1 "github.com/fluxcd/source-controller/api/v1"
5959

6060
image_automationv1 "github.com/fluxcd/image-automation-controller/api/v1beta2"
61-
"github.com/fluxcd/image-automation-controller/pkg/update"
61+
"github.com/fluxcd/image-automation-controller/internal/update"
6262
)
6363

6464
var (

internal/controller/imageupdateautomation_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"sigs.k8s.io/controller-runtime/pkg/predicate"
4040
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4141

42-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
42+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
4343
aclapi "github.com/fluxcd/pkg/apis/acl"
4444
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
4545
"github.com/fluxcd/pkg/apis/meta"
@@ -152,7 +152,7 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(ctx context.Context,
152152
builder.WithPredicates(sourceConfigChangePredicate{}),
153153
).
154154
Watches(
155-
&imagev1_reflect.ImagePolicy{},
155+
&reflectorv1.ImagePolicy{},
156156
handler.EnqueueRequestsFromMapFunc(r.automationsForImagePolicy),
157157
builder.WithPredicates(latestImageChangePredicate{}),
158158
).
@@ -549,7 +549,7 @@ func (r *ImageUpdateAutomationReconciler) reconcileDelete(obj *imagev1.ImageUpda
549549

550550
// getPolicies returns list of policies in the given namespace that have latest
551551
// image.
552-
func getPolicies(ctx context.Context, kclient client.Client, namespace string, selector *metav1.LabelSelector) ([]imagev1_reflect.ImagePolicy, error) {
552+
func getPolicies(ctx context.Context, kclient client.Client, namespace string, selector *metav1.LabelSelector) ([]reflectorv1.ImagePolicy, error) {
553553
policySelector := labels.Everything()
554554
var err error
555555
if selector != nil {
@@ -558,12 +558,12 @@ func getPolicies(ctx context.Context, kclient client.Client, namespace string, s
558558
}
559559
}
560560

561-
var policies imagev1_reflect.ImagePolicyList
561+
var policies reflectorv1.ImagePolicyList
562562
if err := kclient.List(ctx, &policies, &client.ListOptions{Namespace: namespace, LabelSelector: policySelector}); err != nil {
563563
return nil, fmt.Errorf("failed to list policies: %w", err)
564564
}
565565

566-
readyPolicies := []imagev1_reflect.ImagePolicy{}
566+
readyPolicies := []reflectorv1.ImagePolicy{}
567567
for _, policy := range policies.Items {
568568
// Ignore the policies that don't have a latest image.
569569
if policy.Status.LatestRef == nil {

internal/controller/imageupdateautomation_controller_test.go

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
4646
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
4747

48-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
48+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
4949
aclapi "github.com/fluxcd/pkg/apis/acl"
5050
"github.com/fluxcd/pkg/apis/meta"
5151
"github.com/fluxcd/pkg/gittestserver"
@@ -58,7 +58,6 @@ import (
5858
imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta2"
5959
"github.com/fluxcd/image-automation-controller/internal/source"
6060
"github.com/fluxcd/image-automation-controller/internal/testutil"
61-
"github.com/fluxcd/image-automation-controller/pkg/test"
6261
)
6362

6463
const (
@@ -141,12 +140,12 @@ func TestImageUpdateAutomationReconciler_deleteBeforeFinalizer(t *testing.T) {
141140
func TestImageUpdateAutomationReconciler_watchSourceAndLatestImage(t *testing.T) {
142141
g := NewWithT(t)
143142

144-
policySpec := imagev1_reflect.ImagePolicySpec{
143+
policySpec := reflectorv1.ImagePolicySpec{
145144
ImageRepositoryRef: meta.NamespacedObjectReference{
146145
Name: "not-expected-to-exist",
147146
},
148-
Policy: imagev1_reflect.ImagePolicyChoice{
149-
SemVer: &imagev1_reflect.SemVerPolicy{
147+
Policy: reflectorv1.ImagePolicyChoice{
148+
SemVer: &reflectorv1.SemVerPolicy{
150149
Range: "1.x",
151150
},
152151
},
@@ -267,12 +266,12 @@ func TestImageUpdateAutomationReconciler_suspended(t *testing.T) {
267266
}
268267

269268
func TestImageUpdateAutomationReconciler_Reconcile(t *testing.T) {
270-
policySpec := imagev1_reflect.ImagePolicySpec{
269+
policySpec := reflectorv1.ImagePolicySpec{
271270
ImageRepositoryRef: meta.NamespacedObjectReference{
272271
Name: "not-expected-to-exist",
273272
},
274-
Policy: imagev1_reflect.ImagePolicyChoice{
275-
SemVer: &imagev1_reflect.SemVerPolicy{
273+
Policy: reflectorv1.ImagePolicyChoice{
274+
SemVer: &reflectorv1.SemVerPolicy{
276275
Range: "1.x",
277276
},
278277
},
@@ -707,12 +706,12 @@ func TestImageUpdateAutomationReconciler_Reconcile(t *testing.T) {
707706
}
708707

709708
func TestImageUpdateAutomationReconciler_commitMessage(t *testing.T) {
710-
policySpec := imagev1_reflect.ImagePolicySpec{
709+
policySpec := reflectorv1.ImagePolicySpec{
711710
ImageRepositoryRef: meta.NamespacedObjectReference{
712711
Name: "not-expected-to-exist",
713712
},
714-
Policy: imagev1_reflect.ImagePolicyChoice{
715-
SemVer: &imagev1_reflect.SemVerPolicy{
713+
Policy: reflectorv1.ImagePolicyChoice{
714+
SemVer: &reflectorv1.SemVerPolicy{
716715
Range: "1.x",
717716
},
718717
},
@@ -845,12 +844,12 @@ Automation: %s/update-test
845844

846845
// TestImageUpdateAutomationReconciler_removedTemplateField tests removed template field usage (.Updated and .Changed.ImageResult).
847846
func TestImageUpdateAutomationReconciler_removedTemplateField(t *testing.T) {
848-
policySpec := imagev1_reflect.ImagePolicySpec{
847+
policySpec := reflectorv1.ImagePolicySpec{
849848
ImageRepositoryRef: meta.NamespacedObjectReference{
850849
Name: "not-expected-to-exist",
851850
},
852-
Policy: imagev1_reflect.ImagePolicyChoice{
853-
SemVer: &imagev1_reflect.SemVerPolicy{
851+
Policy: reflectorv1.ImagePolicyChoice{
852+
SemVer: &reflectorv1.SemVerPolicy{
854853
Range: "1.x",
855854
},
856855
},
@@ -973,12 +972,12 @@ Images:
973972

974973
func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
975974
g := NewWithT(t)
976-
policySpec := imagev1_reflect.ImagePolicySpec{
975+
policySpec := reflectorv1.ImagePolicySpec{
977976
ImageRepositoryRef: meta.NamespacedObjectReference{
978977
Name: "not-expected-to-exist",
979978
},
980-
Policy: imagev1_reflect.ImagePolicyChoice{
981-
SemVer: &imagev1_reflect.SemVerPolicy{
979+
Policy: reflectorv1.ImagePolicyChoice{
980+
SemVer: &reflectorv1.SemVerPolicy{
982981
Range: "1.x",
983982
},
984983
},
@@ -1056,7 +1055,7 @@ func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
10561055
r := &ImageUpdateAutomationReconciler{
10571056
Client: fakeclient.NewClientBuilder().
10581057
WithScheme(testEnv.Scheme()).
1059-
WithStatusSubresource(&imagev1.ImageUpdateAutomation{}, &imagev1_reflect.ImagePolicy{}).
1058+
WithStatusSubresource(&imagev1.ImageUpdateAutomation{}, &reflectorv1.ImagePolicy{}).
10601059
Build(),
10611060
EventRecorder: testEnv.GetEventRecorderFor("image-automation-controller"),
10621061
NoCrossNamespaceRef: true,
@@ -1105,12 +1104,12 @@ func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
11051104
}
11061105

11071106
func TestImageUpdateAutomationReconciler_updatePath(t *testing.T) {
1108-
policySpec := imagev1_reflect.ImagePolicySpec{
1107+
policySpec := reflectorv1.ImagePolicySpec{
11091108
ImageRepositoryRef: meta.NamespacedObjectReference{
11101109
Name: "not-expected-to-exist",
11111110
},
1112-
Policy: imagev1_reflect.ImagePolicyChoice{
1113-
SemVer: &imagev1_reflect.SemVerPolicy{
1111+
Policy: reflectorv1.ImagePolicyChoice{
1112+
SemVer: &reflectorv1.SemVerPolicy{
11141113
Range: "1.x",
11151114
},
11161115
},
@@ -1187,12 +1186,12 @@ func TestImageUpdateAutomationReconciler_updatePath(t *testing.T) {
11871186
}
11881187

11891188
func TestImageUpdateAutomationReconciler_signedCommit(t *testing.T) {
1190-
policySpec := imagev1_reflect.ImagePolicySpec{
1189+
policySpec := reflectorv1.ImagePolicySpec{
11911190
ImageRepositoryRef: meta.NamespacedObjectReference{
11921191
Name: "not-expected-to-exist",
11931192
},
1194-
Policy: imagev1_reflect.ImagePolicyChoice{
1195-
SemVer: &imagev1_reflect.SemVerPolicy{
1193+
Policy: reflectorv1.ImagePolicyChoice{
1194+
SemVer: &reflectorv1.SemVerPolicy{
11961195
Range: "1.x",
11971196
},
11981197
},
@@ -1722,10 +1721,10 @@ func Test_getPolicies(t *testing.T) {
17221721
// Create all the test policies.
17231722
testObjects := []client.Object{}
17241723
for _, p := range tt.policies {
1725-
aPolicy := &imagev1_reflect.ImagePolicy{}
1724+
aPolicy := &reflectorv1.ImagePolicy{}
17261725
aPolicy.Name = p.name
17271726
aPolicy.Namespace = p.namespace
1728-
aPolicy.Status = imagev1_reflect.ImagePolicyStatus{
1727+
aPolicy.Status = reflectorv1.ImagePolicyStatus{
17291728
LatestRef: testutil.ImageToRef(p.latestImage),
17301729
}
17311730
aPolicy.Labels = p.labels
@@ -1846,7 +1845,7 @@ func compareRepoWithExpected(ctx context.Context, g *WithT, repoURL, branch, fix
18461845
defer wt.Filesystem.Remove(".")
18471846

18481847
g.Expect(err).ToNot(HaveOccurred())
1849-
test.ExpectMatchingDirectories(g, wt.Filesystem.Root(), expected)
1848+
testutil.ExpectMatchingDirectories(g, wt.Filesystem.Root(), expected)
18501849
}
18511850

18521851
func waitForNewHead(g *WithT, repo *extgogit.Repository, branch, preChangeHash string) {
@@ -1938,7 +1937,7 @@ func testWithRepoAndImagePolicy(
19381937
kClient client.Client,
19391938
namespace string,
19401939
fixture string,
1941-
policySpec imagev1_reflect.ImagePolicySpec,
1940+
policySpec reflectorv1.ImagePolicySpec,
19421941
latest string,
19431942
testFunc testWithRepoAndImagePolicyTestFunc) {
19441943
// Generate unique repo and policy arguments.
@@ -1955,7 +1954,7 @@ func testWithCustomRepoAndImagePolicy(
19551954
g *WithT,
19561955
kClient client.Client,
19571956
fixture string,
1958-
policySpec imagev1_reflect.ImagePolicySpec,
1957+
policySpec reflectorv1.ImagePolicySpec,
19591958
latest string,
19601959
args repoAndPolicyArgs,
19611960
testFunc testWithRepoAndImagePolicyTestFunc) {
@@ -2013,21 +2012,21 @@ func createGitRepository(ctx context.Context, kClient client.Client, name, names
20132012
}
20142013

20152014
func createImagePolicyWithLatestImage(ctx context.Context, kClient client.Client, name, namespace, repoRef, semverRange, latest string) error {
2016-
policySpec := imagev1_reflect.ImagePolicySpec{
2015+
policySpec := reflectorv1.ImagePolicySpec{
20172016
ImageRepositoryRef: meta.NamespacedObjectReference{
20182017
Name: repoRef,
20192018
},
2020-
Policy: imagev1_reflect.ImagePolicyChoice{
2021-
SemVer: &imagev1_reflect.SemVerPolicy{
2019+
Policy: reflectorv1.ImagePolicyChoice{
2020+
SemVer: &reflectorv1.SemVerPolicy{
20222021
Range: semverRange,
20232022
},
20242023
},
20252024
}
20262025
return createImagePolicyWithLatestImageForSpec(ctx, kClient, name, namespace, policySpec, latest)
20272026
}
20282027

2029-
func createImagePolicyWithLatestImageForSpec(ctx context.Context, kClient client.Client, name, namespace string, policySpec imagev1_reflect.ImagePolicySpec, latest string) error {
2030-
policy := &imagev1_reflect.ImagePolicy{
2028+
func createImagePolicyWithLatestImageForSpec(ctx context.Context, kClient client.Client, name, namespace string, policySpec reflectorv1.ImagePolicySpec, latest string) error {
2029+
policy := &reflectorv1.ImagePolicy{
20312030
Spec: policySpec,
20322031
}
20332032
policy.Name = name
@@ -2042,7 +2041,7 @@ func createImagePolicyWithLatestImageForSpec(ctx context.Context, kClient client
20422041
}
20432042

20442043
func updateImagePolicyWithLatestImage(ctx context.Context, kClient client.Client, name, namespace, latest string) error {
2045-
policy := &imagev1_reflect.ImagePolicy{}
2044+
policy := &reflectorv1.ImagePolicy{}
20462045
key := types.NamespacedName{
20472046
Name: name,
20482047
Namespace: namespace,
@@ -2107,7 +2106,7 @@ func deleteImageUpdateAutomation(ctx context.Context, kClient client.Client, nam
21072106
}
21082107

21092108
func deleteImagePolicy(ctx context.Context, kClient client.Client, name, namespace string) error {
2110-
imagePolicy := &imagev1_reflect.ImagePolicy{}
2109+
imagePolicy := &reflectorv1.ImagePolicy{}
21112110
imagePolicy.Name = name
21122111
imagePolicy.Namespace = namespace
21132112
return kClient.Delete(ctx, imagePolicy)

internal/controller/predicate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sigs.k8s.io/controller-runtime/pkg/event"
2121
"sigs.k8s.io/controller-runtime/pkg/predicate"
2222

23-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
23+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
2424
)
2525

2626
// latestImageChangePredicate implements a predicate for latest image change.
@@ -43,12 +43,12 @@ func (latestImageChangePredicate) Update(e event.UpdateEvent) bool {
4343
return false
4444
}
4545

46-
oldSource, ok := e.ObjectOld.(*imagev1_reflect.ImagePolicy)
46+
oldSource, ok := e.ObjectOld.(*reflectorv1.ImagePolicy)
4747
if !ok {
4848
return false
4949
}
5050

51-
newSource, ok := e.ObjectNew.(*imagev1_reflect.ImagePolicy)
51+
newSource, ok := e.ObjectNew.(*reflectorv1.ImagePolicy)
5252
if !ok {
5353
return false
5454
}

internal/controller/predicate_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ import (
2222
. "github.com/onsi/gomega"
2323
"sigs.k8s.io/controller-runtime/pkg/event"
2424

25-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
25+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
2626
sourcev1 "github.com/fluxcd/source-controller/api/v1"
2727
)
2828

2929
func Test_latestImageChangePredicate_Update(t *testing.T) {
3030
tests := []struct {
3131
name string
32-
beforeFunc func(oldObj, newObj *imagev1_reflect.ImagePolicy)
32+
beforeFunc func(oldObj, newObj *reflectorv1.ImagePolicy)
3333
want bool
3434
}{
3535
{
3636
name: "no latest image",
37-
beforeFunc: func(oldObj, newObj *imagev1_reflect.ImagePolicy) {
37+
beforeFunc: func(oldObj, newObj *reflectorv1.ImagePolicy) {
3838
oldObj.Status.LatestRef = nil
3939
newObj.Status.LatestRef = nil
4040
},
4141
want: false,
4242
},
4343
{
4444
name: "new image, no old image",
45-
beforeFunc: func(oldObj, newObj *imagev1_reflect.ImagePolicy) {
45+
beforeFunc: func(oldObj, newObj *reflectorv1.ImagePolicy) {
4646
oldObj.Status.LatestRef = nil
47-
newObj.Status.LatestRef = &imagev1_reflect.ImageRef{Name: "foo"}
47+
newObj.Status.LatestRef = &reflectorv1.ImageRef{Name: "foo"}
4848
},
4949
want: true,
5050
},
5151
{
5252
name: "different old and new image",
53-
beforeFunc: func(oldObj, newObj *imagev1_reflect.ImagePolicy) {
54-
oldObj.Status.LatestRef = &imagev1_reflect.ImageRef{Name: "bar"}
55-
newObj.Status.LatestRef = &imagev1_reflect.ImageRef{Name: "foo"}
53+
beforeFunc: func(oldObj, newObj *reflectorv1.ImagePolicy) {
54+
oldObj.Status.LatestRef = &reflectorv1.ImageRef{Name: "bar"}
55+
newObj.Status.LatestRef = &reflectorv1.ImageRef{Name: "foo"}
5656
},
5757
want: true,
5858
},
@@ -61,7 +61,7 @@ func Test_latestImageChangePredicate_Update(t *testing.T) {
6161
t.Run(tt.name, func(t *testing.T) {
6262
g := NewWithT(t)
6363

64-
oldObj := &imagev1_reflect.ImagePolicy{}
64+
oldObj := &reflectorv1.ImagePolicy{}
6565
newObj := oldObj.DeepCopy()
6666
if tt.beforeFunc != nil {
6767
tt.beforeFunc(oldObj, newObj)

internal/controller/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
ctrl "sigs.k8s.io/controller-runtime"
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232

33-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
33+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
3434
"github.com/fluxcd/pkg/runtime/controller"
3535
"github.com/fluxcd/pkg/runtime/testenv"
3636
sourcev1 "github.com/fluxcd/source-controller/api/v1"
@@ -56,7 +56,7 @@ func init() {
5656
}
5757

5858
func TestMain(m *testing.M) {
59-
utilruntime.Must(imagev1_reflect.AddToScheme(scheme.Scheme))
59+
utilruntime.Must(reflectorv1.AddToScheme(scheme.Scheme))
6060
utilruntime.Must(sourcev1.AddToScheme(scheme.Scheme))
6161
utilruntime.Must(imagev1.AddToScheme(scheme.Scheme))
6262

internal/policy/applier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"github.com/fluxcd/pkg/runtime/logger"
2626
"sigs.k8s.io/controller-runtime/pkg/log"
2727

28-
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
28+
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
2929

3030
imagev1 "github.com/fluxcd/image-automation-controller/api/v1beta2"
31-
"github.com/fluxcd/image-automation-controller/pkg/update"
31+
"github.com/fluxcd/image-automation-controller/internal/update"
3232
)
3333

3434
var (
@@ -42,7 +42,7 @@ var (
4242

4343
// ApplyPolicies applies the given set of policies on the source present in the
4444
// workDir based on the provided ImageUpdateAutomation configuration.
45-
func ApplyPolicies(ctx context.Context, workDir string, obj *imagev1.ImageUpdateAutomation, policies []imagev1_reflect.ImagePolicy) (update.Result, error) {
45+
func ApplyPolicies(ctx context.Context, workDir string, obj *imagev1.ImageUpdateAutomation, policies []reflectorv1.ImagePolicy) (update.Result, error) {
4646
var result update.Result
4747
if obj.Spec.Update == nil {
4848
return result, ErrNoUpdateStrategy

0 commit comments

Comments
 (0)