@@ -29,6 +29,7 @@ import (
2929
3030 corev1 "k8s.io/api/core/v1"
3131 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
32+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3233 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3334 "k8s.io/apimachinery/pkg/types"
3435 "k8s.io/utils/ptr"
@@ -37,9 +38,11 @@ import (
3738 "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder"
3839 memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
3940 topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
41+ keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4042 condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4143 util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
4244 mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
45+ mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
4346)
4447
4548var _ = Describe ("Cinder controller" , func () {
@@ -1744,4 +1747,125 @@ var _ = Describe("Cinder Webhook", func() {
17441747 return instance , fmt .Sprintf ("cinderVolumes[%s].topologyRef" , instance )
17451748 }),
17461749 )
1750+
1751+ When ("An ApplicationCredential is created for Cinder" , func () {
1752+ var (
1753+ acName string
1754+ acSecretName string
1755+ servicePasswordSecret string
1756+ passwordSelector string
1757+ )
1758+ BeforeEach (func () {
1759+ servicePasswordSecret = "ac-test-osp-secret" //nolint:gosec // G101
1760+ passwordSelector = "CinderPassword"
1761+
1762+ DeferCleanup (k8sClient .Delete , ctx ,
1763+ CreateCinderMessageBusSecret (
1764+ cinderTest .Instance .Namespace ,
1765+ cinderTest .RabbitmqSecretName ,
1766+ ),
1767+ )
1768+ DeferCleanup (k8sClient .Delete , ctx ,
1769+ CreateCinderSecret (
1770+ cinderTest .Instance .Namespace , servicePasswordSecret ))
1771+ // Create Cinder using the service password secret
1772+ spec := GetDefaultCinderSpec ()
1773+ spec ["secret" ] = servicePasswordSecret
1774+ DeferCleanup (th .DeleteInstance , CreateCinder (cinderTest .Instance , spec ))
1775+ DeferCleanup (
1776+ mariadb .DeleteDBService ,
1777+ mariadb .CreateDBService (
1778+ cinderTest .Instance .Namespace ,
1779+ GetCinder (cinderTest .Instance ).Spec .DatabaseInstance ,
1780+ corev1.ServiceSpec {
1781+ Ports : []corev1.ServicePort {{Port : 3306 }}}))
1782+ DeferCleanup (keystone .DeleteKeystoneAPI ,
1783+ keystone .CreateKeystoneAPI (cinderTest .Instance .Namespace ),
1784+ )
1785+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (cinderTest .Instance .Namespace , MemcachedInstance , memcachedv1.MemcachedSpec {}))
1786+ infra .SimulateMemcachedReady (cinderTest .CinderMemcached )
1787+
1788+ // Create MariaDB account and database
1789+ acc , accSecret := mariadb .CreateMariaDBAccountAndSecret (cinderTest .Database , mariadbv1.MariaDBAccountSpec {})
1790+ DeferCleanup (k8sClient .Delete , ctx , acc )
1791+ DeferCleanup (k8sClient .Delete , ctx , accSecret )
1792+ mariadb .CreateMariaDBDatabase (cinderTest .Database .Namespace , cinderTest .Database .Name , mariadbv1.MariaDBDatabaseSpec {})
1793+ DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (cinderTest .Database ))
1794+
1795+ acName = fmt .Sprintf ("ac-%s" , cinder .ServiceName )
1796+ acSecretName = acName + "-secret"
1797+ secret := & corev1.Secret {
1798+ ObjectMeta : metav1.ObjectMeta {
1799+ Namespace : cinderTest .Instance .Namespace ,
1800+ Name : acSecretName ,
1801+ },
1802+ Data : map [string ][]byte {
1803+ "AC_ID" : []byte ("test-ac-id" ),
1804+ "AC_SECRET" : []byte ("test-ac-secret" ),
1805+ },
1806+ }
1807+ DeferCleanup (k8sClient .Delete , ctx , secret )
1808+ Expect (k8sClient .Create (ctx , secret )).To (Succeed ())
1809+
1810+ ac := & keystonev1.KeystoneApplicationCredential {
1811+ ObjectMeta : metav1.ObjectMeta {
1812+ Namespace : cinderTest .Instance .Namespace ,
1813+ Name : acName ,
1814+ },
1815+ Spec : keystonev1.KeystoneApplicationCredentialSpec {
1816+ UserName : cinder .ServiceName ,
1817+ Secret : servicePasswordSecret ,
1818+ PasswordSelector : passwordSelector ,
1819+ Roles : []string {"admin" , "member" },
1820+ AccessRules : []keystonev1.ACRule {{Service : "identity" , Method : "POST" , Path : "/auth/tokens" }},
1821+ ExpirationDays : 30 ,
1822+ GracePeriodDays : 5 ,
1823+ },
1824+ }
1825+ DeferCleanup (k8sClient .Delete , ctx , ac )
1826+ Expect (k8sClient .Create (ctx , ac )).To (Succeed ())
1827+
1828+ fetched := & keystonev1.KeystoneApplicationCredential {}
1829+ key := types.NamespacedName {Namespace : ac .Namespace , Name : ac .Name }
1830+ Expect (k8sClient .Get (ctx , key , fetched )).To (Succeed ())
1831+
1832+ fetched .Status .SecretName = acSecretName
1833+ now := metav1 .Now ()
1834+ readyCond := condition.Condition {
1835+ Type : condition .ReadyCondition ,
1836+ Status : corev1 .ConditionTrue ,
1837+ Reason : condition .ReadyReason ,
1838+ Message : condition .ReadyMessage ,
1839+ LastTransitionTime : now ,
1840+ }
1841+ fetched .Status .Conditions = condition.Conditions {readyCond }
1842+ Expect (k8sClient .Status ().Update (ctx , fetched )).To (Succeed ())
1843+
1844+ infra .SimulateTransportURLReady (cinderTest .CinderTransportURL )
1845+ mariadb .SimulateMariaDBAccountCompleted (cinderTest .Database )
1846+ mariadb .SimulateMariaDBDatabaseCompleted (cinderTest .Database )
1847+
1848+ th .SimulateJobSuccess (cinderTest .CinderDBSync )
1849+
1850+ keystone .SimulateKeystoneEndpointReady (cinderTest .CinderKeystoneEndpoint )
1851+ })
1852+
1853+ It ("should render ApplicationCredential auth in 00-global-defaults.conf" , func () {
1854+ keystone .SimulateKeystoneEndpointReady (cinderTest .CinderKeystoneEndpoint )
1855+
1856+ Eventually (func (g Gomega ) {
1857+ cfgSecret := th .GetSecret (cinderTest .CinderConfigSecret )
1858+ g .Expect (cfgSecret ).NotTo (BeNil ())
1859+
1860+ conf := string (cfgSecret .Data ["00-global-defaults.conf" ])
1861+
1862+ g .Expect (conf ).To (ContainSubstring (
1863+ "application_credential_id = test-ac-id" ),
1864+ )
1865+ g .Expect (conf ).To (ContainSubstring (
1866+ "application_credential_secret = test-ac-secret" ),
1867+ )
1868+ }, timeout , interval ).Should (Succeed ())
1869+ })
1870+ })
17471871})
0 commit comments