@@ -19,15 +19,18 @@ package functional
1919import (
2020 "fmt"
2121 "os"
22+ "time"
2223
2324 appsv1 "k8s.io/api/apps/v1"
2425 "k8s.io/apimachinery/pkg/types"
2526
2627 . "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports
2728 . "github.com/onsi/gomega" //revive:disable:dot-imports
2829 glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
30+ "github.com/openstack-k8s-operators/glance-operator/pkg/glance"
2931 memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
3032 topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
33+ keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
3134 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3235
3336 //revive:disable-next-line:dot-imports
@@ -1286,4 +1289,116 @@ var _ = Describe("Glanceapi controller", func() {
12861289 }, timeout , interval ).Should (Succeed ())
12871290 })
12881291 })
1292+
1293+ When ("An ApplicationCredential is created for Glance" , func () {
1294+ var (
1295+ acName string
1296+ acSecretName string
1297+ servicePasswordSecret string
1298+ passwordSelector string
1299+ )
1300+ BeforeEach (func () {
1301+ servicePasswordSecret = "ac-test-osp-secret" //nolint:gosec // G101
1302+ passwordSelector = "GlancePassword"
1303+
1304+ DeferCleanup (k8sClient .Delete , ctx , CreateGlanceSecret (glanceTest .Instance .Namespace , servicePasswordSecret ))
1305+ DeferCleanup (k8sClient .Delete , ctx , CreateGlanceMessageBusSecret (glanceTest .Instance .Namespace , glanceTest .RabbitmqSecretName ))
1306+ DeferCleanup (th .DeleteInstance , CreateDefaultGlance (glanceTest .Instance ))
1307+ DeferCleanup (
1308+ mariadb .DeleteDBService ,
1309+ mariadb .CreateDBService (
1310+ glanceTest .Instance .Namespace ,
1311+ glanceTest .GlanceDatabaseName .Name ,
1312+ corev1.ServiceSpec {
1313+ Ports : []corev1.ServicePort {{Port : 3306 }}}))
1314+ mariadb .CreateMariaDBDatabase (glanceTest .GlanceDatabaseName .Namespace , glanceTest .GlanceDatabaseName .Name , mariadbv1.MariaDBDatabaseSpec {})
1315+ DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (glanceTest .GlanceDatabaseName ))
1316+
1317+ DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (glanceTest .Instance .Namespace ))
1318+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (glanceTest .Instance .Namespace , MemcachedInstance , memcachedv1.MemcachedSpec {}))
1319+ infra .SimulateMemcachedReady (glanceTest .GlanceMemcached )
1320+
1321+ // Create AC secret with test credentials
1322+ acName = fmt .Sprintf ("ac-%s" , glance .ServiceName )
1323+ acSecretName = acName + "-secret"
1324+ acSecret := & corev1.Secret {
1325+ ObjectMeta : metav1.ObjectMeta {
1326+ Namespace : glanceTest .Instance .Namespace ,
1327+ Name : acSecretName ,
1328+ },
1329+ Data : map [string ][]byte {
1330+ "AC_ID" : []byte ("test-ac-id" ),
1331+ "AC_SECRET" : []byte ("test-ac-secret" ),
1332+ },
1333+ }
1334+ DeferCleanup (k8sClient .Delete , ctx , acSecret )
1335+ Expect (k8sClient .Create (ctx , acSecret )).To (Succeed ())
1336+
1337+ // Create AC CR
1338+ ac := & keystonev1.KeystoneApplicationCredential {
1339+ ObjectMeta : metav1.ObjectMeta {
1340+ Namespace : glanceTest .Instance .Namespace ,
1341+ Name : acName ,
1342+ },
1343+ Spec : keystonev1.KeystoneApplicationCredentialSpec {
1344+ UserName : glance .ServiceName ,
1345+ Secret : servicePasswordSecret ,
1346+ PasswordSelector : passwordSelector ,
1347+ Roles : []string {"admin" , "member" },
1348+ AccessRules : []keystonev1.ACRule {{Service : "identity" , Method : "POST" , Path : "/auth/tokens" }},
1349+ ExpirationDays : 30 ,
1350+ GracePeriodDays : 5 ,
1351+ },
1352+ }
1353+ DeferCleanup (k8sClient .Delete , ctx , ac )
1354+ Expect (k8sClient .Create (ctx , ac )).To (Succeed ())
1355+
1356+ // Simulate AC controller updating the status
1357+ fetched := & keystonev1.KeystoneApplicationCredential {}
1358+ key := types.NamespacedName {Namespace : ac .Namespace , Name : ac .Name }
1359+ Expect (k8sClient .Get (ctx , key , fetched )).To (Succeed ())
1360+
1361+ fetched .Status .SecretName = acSecretName
1362+ now := metav1 .Now ()
1363+ readyCond := condition.Condition {
1364+ Type : condition .ReadyCondition ,
1365+ Status : corev1 .ConditionTrue ,
1366+ Reason : condition .ReadyReason ,
1367+ Message : condition .ReadyMessage ,
1368+ LastTransitionTime : now ,
1369+ }
1370+ fetched .Status .Conditions = condition.Conditions {readyCond }
1371+ Expect (k8sClient .Status ().Update (ctx , fetched )).To (Succeed ())
1372+
1373+ // Create GlanceAPI using the service password secret
1374+ spec := CreateGlanceAPISpec (GlanceAPITypeInternal )
1375+ spec ["secret" ] = servicePasswordSecret
1376+ DeferCleanup (th .DeleteInstance , CreateGlanceAPI (glanceTest .GlanceInternal , spec ))
1377+
1378+ mariadb .SimulateMariaDBAccountCompleted (glanceTest .GlanceDatabaseAccount )
1379+ mariadb .SimulateMariaDBDatabaseCompleted (glanceTest .GlanceDatabaseName )
1380+ th .SimulateStatefulSetReplicaReady (glanceTest .GlanceInternalStatefulSet )
1381+
1382+ keystone .SimulateKeystoneEndpointReady (glanceTest .GlanceInternal )
1383+ })
1384+
1385+ It ("should render ApplicationCredential auth in 00-config.conf" , func () {
1386+ keystone .SimulateKeystoneEndpointReady (glanceTest .GlanceInternal )
1387+
1388+ // Wait for the config to be generated and updated with AC auth
1389+ Eventually (func (g Gomega ) {
1390+ cfgSecret := th .GetSecret (glanceTest .GlanceInternalConfigMapData )
1391+ g .Expect (cfgSecret ).NotTo (BeNil ())
1392+
1393+ conf := string (cfgSecret .Data ["00-config.conf" ])
1394+
1395+ g .Expect (conf ).To (ContainSubstring (
1396+ "application_credential_id = test-ac-id" ),
1397+ )
1398+ g .Expect (conf ).To (ContainSubstring (
1399+ "application_credential_secret = test-ac-secret" ),
1400+ )
1401+ }, 30 * time .Second , interval ).Should (Succeed ())
1402+ })
1403+ })
12891404})
0 commit comments