@@ -20,10 +20,14 @@ import (
2020 argov1alpha1 "github.com/cnoe-io/argocd-api/api/argo/application/v1alpha1"
2121 "github.com/cnoe-io/idpbuilder/pkg/k8s"
2222 "github.com/cnoe-io/idpbuilder/pkg/printer/types"
23+ corev1 "k8s.io/api/core/v1"
24+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325 "github.com/stretchr/testify/assert"
2426 "github.com/stretchr/testify/require"
2527 "k8s.io/client-go/tools/clientcmd"
2628 "k8s.io/client-go/util/homedir"
29+ "k8s.io/client-go/util/retry"
30+ "k8s.io/apimachinery/pkg/util/wait"
2731 "sigs.k8s.io/controller-runtime/pkg/client"
2832)
2933
@@ -405,3 +409,75 @@ func TestGiteaRegistry(ctx context.Context, t *testing.T, cmd, giteaHost, giteaP
405409 pull , err := RunCommand (ctx , fmt .Sprintf ("%s pull %s" , cmd , tag ), 10 * time .Second )
406410 require .NoErrorf (t , err , "%s pull err: %s" , cmd , pull )
407411}
412+
413+ // login, build a test image, push, then pull.
414+ func TestGiteaRegistryInCluster (ctx context.Context , t * testing.T , cmd , giteaHost , giteaPort string , kubeClient client.Client ) {
415+ t .Log ("testing using gitea container registry in cluster" )
416+ b , err := RunCommand (ctx , fmt .Sprintf ("%s get secrets -o json -p gitea" , IdpbuilderBinaryLocation ), 10 * time .Second )
417+ assert .NoError (t , err )
418+
419+ secs := make ([]types.Secret , 1 )
420+ err = json .Unmarshal (b , & secs )
421+ assert .NoError (t , err )
422+
423+ sec := secs [0 ]
424+ user := sec .Username
425+ pass := sec .Password
426+
427+ login , err := RunCommand (ctx , fmt .Sprintf ("%s login %s:%s -u %s -p %s" , cmd , giteaHost , giteaPort , user , pass ), 10 * time .Second )
428+ require .NoErrorf (t , err , "%s login err: %s" , cmd , login )
429+
430+ upstreamImage := "nginx"
431+ tag := fmt .Sprintf ("%s:%s/giteaadmin/nginx:latest" , giteaHost , giteaPort )
432+
433+ pull , err := RunCommand (ctx , fmt .Sprintf ("%s pull %s" , cmd , upstreamImage ), 10 * time .Second )
434+ require .NoErrorf (t , err , "%s pull err: %s" , cmd , pull )
435+
436+ retag , err := RunCommand (ctx , fmt .Sprintf ("%s tag %s %s" , cmd , upstreamImage , tag ), 10 * time .Second )
437+ require .NoErrorf (t , err , "%s tag err: %s" , cmd , retag )
438+
439+ push , err := RunCommand (ctx , fmt .Sprintf ("%s push %s" , cmd , tag ), 10 * time .Second )
440+ require .NoErrorf (t , err , "%s push err: %s" , cmd , push )
441+
442+ pod := & corev1.Pod {
443+ ObjectMeta : metav1.ObjectMeta {Name : "test-pod" , Namespace : "default" },
444+ Spec : corev1.PodSpec {
445+ Containers : []corev1.Container {{
446+ Name : "nginx" ,
447+ Image : tag ,
448+ }},
449+ },
450+ }
451+
452+ err = kubeClient .Create (ctx , pod )
453+ require .NoErrorf (t , err , "pod creation err" )
454+
455+ // Retry for 30 seconds
456+ backoff := wait.Backoff {
457+ Steps : 3 ,
458+ Duration : 10 * time .Second ,
459+ Jitter : 0.0 ,
460+ }
461+
462+ retriable := func (_ error ) bool {
463+ // Retry all errors
464+ return true
465+ }
466+
467+ testfunc := func () error {
468+ foundPod := & corev1.Pod {}
469+ err = kubeClient .Get (ctx , client.ObjectKey {Name : pod .Name , Namespace : pod .Namespace }, foundPod )
470+ if err != nil {
471+ return err
472+ }
473+
474+ if foundPod .Status .Phase != "Running" {
475+ return fmt .Errorf ("Pod phase not running: %s" , foundPod .Status .Phase )
476+ }
477+
478+ return nil
479+ }
480+
481+ err = retry .OnError (backoff , retriable , testfunc )
482+ require .NoErrorf (t , err , "pod startup err" )
483+ }
0 commit comments