@@ -530,6 +530,72 @@ var _ = Describe("Function Controller", func() {
530530 },
531531 }),
532532 )
533+
534+ It ("should pass ImagePullSecret to deploy when registry authSecretRef is set" , func () {
535+ registrySecretName := "my-registry-secret"
536+
537+ By ("Creating the registry auth secret" )
538+ secret := & v1.Secret {
539+ ObjectMeta : metav1.ObjectMeta {
540+ Name : registrySecretName ,
541+ Namespace : resourceNamespace ,
542+ },
543+ Type : v1 .SecretTypeDockerConfigJson ,
544+ Data : map [string ][]byte {
545+ v1 .DockerConfigJsonKey : []byte (`{"auths":{"registry.example.com":{"auth":"dGVzdDp0ZXN0"}}}` ),
546+ },
547+ }
548+ Expect (k8sClient .Create (ctx , secret )).To (Succeed ())
549+ defer func () { _ = k8sClient .Delete (ctx , secret ) }()
550+
551+ By ("Creating the Function with registry authSecretRef" )
552+ spec := functionsdevv1alpha1.FunctionSpec {
553+ Repository : functionsdevv1alpha1.FunctionSpecRepository {
554+ URL : "https://github.com/foo/bar" ,
555+ Branch : "my-branch" ,
556+ },
557+ Registry : functionsdevv1alpha1.FunctionSpecRegistry {
558+ AuthSecretRef : & v1.LocalObjectReference {
559+ Name : registrySecretName ,
560+ },
561+ },
562+ }
563+ Expect (createFunctionResource (resourceName , resourceNamespace , spec )).To (Succeed ())
564+
565+ By ("Setting up mocks" )
566+ funcCliManagerMock := funccli .NewMockManager (GinkgoT ())
567+ gitManagerMock := git .NewMockManager (GinkgoT ())
568+
569+ funcCliManagerMock .EXPECT ().Describe (mock .Anything , functionName , resourceNamespace ).Return (functions.Instance {
570+ Middleware : functions.Middleware {Version : "v1.0.0" },
571+ }, nil )
572+ funcCliManagerMock .EXPECT ().GetLatestMiddlewareVersion (mock .Anything , mock .Anything , mock .Anything ).Return ("v2.0.0" , nil )
573+
574+ funcCliManagerMock .EXPECT ().Deploy (mock .Anything , mock .Anything , resourceNamespace , mock .MatchedBy (func (opts funccli.DeployOptions ) bool {
575+ return opts .ImagePullSecret == registrySecretName && opts .RegistryAuthFile != ""
576+ })).Return (nil )
577+
578+ gitManagerMock .EXPECT ().CloneRepository (mock .Anything , "https://github.com/foo/bar" , "" , "my-branch" , mock .Anything ).Return (createTmpGitRepo (functions.Function {Name : "func-go" }), nil )
579+
580+ operatorNs := fmt .Sprintf ("func-operator-%s" , rand .String (6 ))
581+ Expect (createNamespace (operatorNs )).To (Succeed ())
582+ Expect (createControllerConfig (operatorNs , nil )).To (Succeed ())
583+
584+ By ("Reconciling" )
585+ controllerReconciler := & FunctionReconciler {
586+ Client : k8sClient ,
587+ Scheme : k8sClient .Scheme (),
588+ Recorder : & events.FakeRecorder {},
589+ FuncCliManager : funcCliManagerMock ,
590+ GitManager : gitManagerMock ,
591+ OperatorNamespace : operatorNs ,
592+ }
593+
594+ _ , err := controllerReconciler .Reconcile (ctx , reconcile.Request {
595+ NamespacedName : typeNamespacedName ,
596+ })
597+ Expect (err ).NotTo (HaveOccurred ())
598+ })
533599 })
534600})
535601
0 commit comments