@@ -79,6 +79,25 @@ func (c *Controller) ensureCapturedState(configuration *terraformv1alpha1.Config
79
79
return reconcile.Result {}, err
80
80
}
81
81
82
+ // @step: if we are based on a Revision, lets try and grab the definition
83
+ if configuration .IsRevisioned () {
84
+ revision := & terraformv1alpha1.Revision {}
85
+ revision .Name = configuration .Spec .Plan .Revision
86
+
87
+ found , err := kubernetes .GetIfExists (ctx , c .cc , revision )
88
+ if err != nil {
89
+ cond .Failed (err , "Failed to retrieve the plan for the configuration" )
90
+
91
+ return reconcile.Result {}, err
92
+ }
93
+ if ! found {
94
+ cond .ActionRequired ("Revision %q does not exist" , configuration .Spec .Plan .Revision )
95
+
96
+ return reconcile.Result {RequeueAfter : 5 * time .Minute }, nil
97
+ }
98
+ state .revision = revision
99
+ }
100
+
82
101
// @step: retrieve a list of all the confugrations in the cluster - shouldn't have much impact
83
102
// as it's a cached client and we defer to the cache
84
103
configurations := & terraformv1alpha1.ConfigurationList {}
@@ -457,29 +476,17 @@ func (c *Controller) ensureAuthenticationSecret(configuration *terraformv1alpha1
457
476
secret := & v1.Secret {}
458
477
secret .Name = configuration .Spec .Auth .Name
459
478
460
- if configuration .Spec .Plan != nil && configuration .Spec .Plan .Name != "" {
461
- // @step: retrieve the revision from the plan
462
- revision := & terraformv1alpha1.Revision {}
463
- revision .Name = configuration .GetLabels ()[terraformv1alpha1 .CloudResourceRevisionNameLabel ]
464
-
465
- found , err := kubernetes .GetIfExists (ctx , c .cc , revision )
466
- if err != nil {
467
- cond .Failed (err , "Failed to retrieve the revision: %q, which this Configuration %q is part of" , revision .Name , configuration .Name )
468
- return reconcile.Result {}, err
469
- }
470
- if ! found {
471
- cond .ActionRequired ("Revision %q, which this Configuration %q is part of, does not exist" , revision .Name , configuration .Name )
472
- return reconcile.Result {RequeueAfter : 5 * time .Minute }, nil
473
- }
479
+ if configuration .IsRevisioned () {
480
+ revision := state .revision
474
481
475
482
// @step: use the auth from the revision (sourcing secret from different namespace) if it's the same as in the configuration
476
483
if revision .Spec .Configuration .Auth != nil {
477
484
if reflect .DeepEqual (revision .Spec .Configuration .Auth , configuration .Spec .Auth ) {
478
485
secret .Namespace = revision .Spec .Configuration .Auth .Namespace
479
486
log .WithFields (log.Fields {
480
- "name" : configuration .Name ,
481
487
"auth_name" : secret .Name ,
482
488
"auth_namespace" : secret .Namespace ,
489
+ "name" : configuration .Name ,
483
490
"revision" : revision .Name ,
484
491
}).Info ("auth secrets match, retrieving from the specified auth namespace, as defined in the revision" )
485
492
} else {
0 commit comments