@@ -11,6 +11,7 @@ import (
11
11
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
12
12
"github.com/fluxcd/pkg/apis/meta"
13
13
fluxMeta "github.com/fluxcd/pkg/apis/meta"
14
+ sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
14
15
"github.com/google/go-cmp/cmp"
15
16
"github.com/google/go-cmp/cmp/cmpopts"
16
17
corev1 "k8s.io/api/core/v1"
@@ -32,6 +33,7 @@ import (
32
33
clustersv1 "github.com/weaveworks/cluster-controller/api/v1alpha1"
33
34
templatesv1 "github.com/weaveworks/gitopssets-controller/api/v1alpha1"
34
35
"github.com/weaveworks/gitopssets-controller/controllers/templates/generators"
36
+ "github.com/weaveworks/gitopssets-controller/controllers/templates/generators/gitrepository"
35
37
"github.com/weaveworks/gitopssets-controller/controllers/templates/generators/list"
36
38
"github.com/weaveworks/gitopssets-controller/test"
37
39
)
@@ -54,6 +56,7 @@ func TestReconciliation(t *testing.T) {
54
56
CRDDirectoryPaths : []string {
55
57
filepath .Join (".." , "config" , "crd" , "bases" ),
56
58
"testdata/crds" ,
59
+ "../tests/e2e/testdata/crds" ,
57
60
},
58
61
}
59
62
testEnv .ControlPlane .GetAPIServer ().Configure ().Append ("--authorization-mode=RBAC" )
@@ -73,6 +76,7 @@ func TestReconciliation(t *testing.T) {
73
76
// Kustomizations.
74
77
test .AssertNoError (t , clientgoscheme .AddToScheme (scheme ))
75
78
test .AssertNoError (t , templatesv1 .AddToScheme (scheme ))
79
+ test .AssertNoError (t , sourcev1beta2 .AddToScheme (scheme ))
76
80
77
81
k8sClient , err := client .New (cfg , client.Options {Scheme : scheme })
78
82
test .AssertNoError (t , err )
@@ -86,7 +90,8 @@ func TestReconciliation(t *testing.T) {
86
90
Scheme : scheme ,
87
91
DefaultServiceAccount : "" ,
88
92
Generators : map [string ]generators.GeneratorFactory {
89
- "List" : list .GeneratorFactory ,
93
+ "List" : list .GeneratorFactory ,
94
+ "GitRepository" : gitrepository .GeneratorFactory (nil ),
90
95
},
91
96
Config : cfg ,
92
97
EventRecorder : eventRecorder ,
@@ -200,7 +205,7 @@ func TestReconciliation(t *testing.T) {
200
205
}
201
206
})
202
207
test .AssertNoError (t , k8sClient .Create (ctx , test .ToUnstructured (t , devKS )))
203
- defer cleanupResource (t , k8sClient , test .ToUnstructured (t , devKS ))
208
+ defer deleteObject (t , k8sClient , test .ToUnstructured (t , devKS ))
204
209
205
210
_ , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : client .ObjectKeyFromObject (gs )})
206
211
test .AssertErrorMatch (t , "failed to create Resource.*already exists" , err )
@@ -731,6 +736,37 @@ func TestReconciliation(t *testing.T) {
731
736
assertNoKustomizationsExistInNamespace (t , k8sClient , "default" )
732
737
})
733
738
739
+ t .Run ("reconciling when gitrepository has no artifact" , func (t * testing.T ) {
740
+ ctx := context .TODO ()
741
+ emptyGR := test .NewGitRepository ()
742
+ test .AssertNoError (t , k8sClient .Create (ctx , test .ToUnstructured (t , emptyGR )))
743
+ defer deleteObject (t , k8sClient , emptyGR )
744
+
745
+ gs := createAndReconcileToFinalizedState (t , k8sClient , reconciler , makeTestGitOpsSet (t , func (gs * templatesv1.GitOpsSet ) {
746
+ gs .Spec .Generators = []templatesv1.GitOpsSetGenerator {
747
+ {
748
+ GitRepository : & templatesv1.GitRepositoryGenerator {
749
+ RepositoryRef : "test-repository" ,
750
+ Files : []templatesv1.RepositoryGeneratorFileItem {
751
+ {Path : "files/dev.yaml" },
752
+ {Path : "files/production.yaml" },
753
+ {Path : "files/staging.yaml" },
754
+ },
755
+ },
756
+ },
757
+ }
758
+ }))
759
+ defer deleteGitOpsSetAndFinalize (t , k8sClient , reconciler , gs )
760
+
761
+ _ , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : client .ObjectKeyFromObject (gs )})
762
+ test .AssertNoError (t , err )
763
+
764
+ test .AssertNoError (t , k8sClient .Get (ctx , client .ObjectKeyFromObject (gs ), gs ))
765
+ assertInventoryHasNoItems (t , gs )
766
+ assertNoKustomizationsExistInNamespace (t , k8sClient , "default" )
767
+ assertGitOpsSetCondition (t , gs , meta .ReadyCondition , "waiting for artifact" )
768
+ })
769
+
734
770
t .Run ("error conditions - existing resource" , func (t * testing.T ) {
735
771
ctx := context .TODO ()
736
772
gs := makeTestGitOpsSet (t , func (gs * templatesv1.GitOpsSet ) {
@@ -760,7 +796,7 @@ func TestReconciliation(t *testing.T) {
760
796
}
761
797
})
762
798
test .AssertNoError (t , k8sClient .Create (ctx , test .ToUnstructured (t , devKS )))
763
- defer cleanupResource (t , k8sClient , gs )
799
+ defer deleteObject (t , k8sClient , gs )
764
800
765
801
_ , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : client .ObjectKeyFromObject (gs )})
766
802
test .AssertErrorMatch (t , "failed to create Resource.*already exists" , err )
@@ -1098,7 +1134,7 @@ func assertInventoryHasNoItems(t *testing.T, gs *templatesv1.GitOpsSet) {
1098
1134
}
1099
1135
}
1100
1136
1101
- func cleanupResource (t * testing.T , cl client.Client , obj client.Object ) {
1137
+ func deleteObject (t * testing.T , cl client.Client , obj client.Object ) {
1102
1138
t .Helper ()
1103
1139
if err := cl .Delete (context .TODO (), obj ); err != nil {
1104
1140
t .Fatal (err )
@@ -1226,7 +1262,7 @@ func createRBACForServiceAccount(t *testing.T, cl client.Client, serviceAccountN
1226
1262
t .Fatalf ("failed to write role: %s" , err )
1227
1263
}
1228
1264
t .Cleanup (func () {
1229
- cleanupResource (t , cl , role )
1265
+ deleteObject (t , cl , role )
1230
1266
})
1231
1267
binding := & rbacv1.RoleBinding {
1232
1268
ObjectMeta : metav1.ObjectMeta {
@@ -1248,7 +1284,7 @@ func createRBACForServiceAccount(t *testing.T, cl client.Client, serviceAccountN
1248
1284
t .Fatalf ("failed to write role-binding: %s" , err )
1249
1285
}
1250
1286
t .Cleanup (func () {
1251
- cleanupResource (t , cl , binding )
1287
+ deleteObject (t , cl , binding )
1252
1288
})
1253
1289
}
1254
1290
func deleteGitOpsSetAndFinalize (t * testing.T , cl client.Client , reconciler * GitOpsSetReconciler , gs * templatesv1.GitOpsSet ) {
0 commit comments