Skip to content

Commit bf98d11

Browse files
author
Joshua Reed
committed
Secrets ref create and fetch test added.
1 parent c73e5b1 commit bf98d11

13 files changed

+97
-9
lines changed

api/v1beta2/cloudstackfailuredomain_types.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

24+
const (
25+
FailuDomainFinalizer = "cloudstackzone.infrastructure.cluster.x-k8s.io"
26+
)
27+
2328
// CloudStackFailureDomainSpec defines the desired state of CloudStackFailureDomain
2429
type CloudStackFailureDomainSpec struct {
2530
// The failure domain unique name.
@@ -36,9 +41,9 @@ type CloudStackFailureDomainSpec struct {
3641
// +optional
3742
Domain string `json:"domain,omitempty"`
3843

39-
// Apache CloudStack Endpoint.
44+
// Apache CloudStack Endpoint secret reference.
4045
// +optional
41-
ACSEndpoint string `json:"ACSEndpoint,omitempty"`
46+
ACSEndpoint corev1.SecretReference `json:"ACSEndpoint,omitempty"`
4247
}
4348

4449
// CloudStackFailureDomainStatus defines the observed state of CloudStackFailureDomain

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackclusters.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,17 @@ spec:
227227
of CloudStackFailureDomain
228228
properties:
229229
ACSEndpoint:
230-
description: Apache CloudStack Endpoint.
231-
type: string
230+
description: Apache CloudStack Endpoint secret reference.
231+
properties:
232+
name:
233+
description: Name is unique within a namespace to reference
234+
a secret resource.
235+
type: string
236+
namespace:
237+
description: Namespace defines the space within which the
238+
secret name must be unique.
239+
type: string
240+
type: object
232241
account:
233242
description: CloudStack account.
234243
type: string

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackfailuredomains.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ spec:
3939
CloudStackFailureDomain
4040
properties:
4141
ACSEndpoint:
42-
description: Apache CloudStack Endpoint.
43-
type: string
42+
description: Apache CloudStack Endpoint secret reference.
43+
properties:
44+
name:
45+
description: Name is unique within a namespace to reference a
46+
secret resource.
47+
type: string
48+
namespace:
49+
description: Namespace defines the space within which the secret
50+
name must be unique.
51+
type: string
52+
type: object
4453
account:
4554
description: CloudStack account.
4655
type: string

controllers/cloudstackaffinitygroup_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"github.com/onsi/ginkgo/v2"
2122

2223
ctrl "sigs.k8s.io/controller-runtime"
2324
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -54,6 +55,7 @@ func NewCSAGReconciliationRunner() *CloudStackAGReconciliationRunner {
5455
}
5556

5657
func (reconciler *CloudStackAffinityGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
58+
defer ginkgo.GinkgoRecover()
5759
return NewCSAGReconciliationRunner().
5860
UsingBaseReconciler(reconciler.ReconcilerBase).
5961
ForRequest(req).
@@ -62,6 +64,7 @@ func (reconciler *CloudStackAffinityGroupReconciler) Reconcile(ctx context.Conte
6264
}
6365

6466
func (r *CloudStackAGReconciliationRunner) Reconcile() (ctrl.Result, error) {
67+
defer ginkgo.GinkgoRecover()
6568
controllerutil.AddFinalizer(r.ReconciliationSubject, infrav1.AffinityGroupFinalizer)
6669
affinityGroup := &cloud.AffinityGroup{Name: r.ReconciliationSubject.Spec.Name, Type: r.ReconciliationSubject.Spec.Type}
6770
if err := r.CSUser.GetOrCreateAffinityGroup(affinityGroup); err != nil {

controllers/cloudstackcluster_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"github.com/onsi/ginkgo/v2"
2223
"reflect"
2324

2425
ctrl "sigs.k8s.io/controller-runtime"
@@ -76,6 +77,7 @@ func NewCSClusterReconciliationRunner() *CloudStackClusterReconciliationRunner {
7677

7778
// Reconcile is the method k8s will call upon a reconciliation request.
7879
func (reconciler *CloudStackClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (retRes ctrl.Result, retErr error) {
80+
defer ginkgo.GinkgoRecover()
7981
return NewCSClusterReconciliationRunner().
8082
UsingBaseReconciler(reconciler.ReconcilerBase).
8183
ForRequest(req).
@@ -85,6 +87,7 @@ func (reconciler *CloudStackClusterReconciler) Reconcile(ctx context.Context, re
8587

8688
// Reconcile actually reconciles the CloudStackCluster.
8789
func (r *CloudStackClusterReconciliationRunner) Reconcile() (res ctrl.Result, reterr error) {
90+
defer ginkgo.GinkgoRecover()
8891
return r.RunReconciliationStages(
8992
r.RequeueIfMissingBaseCRs,
9093
r.CreateFailureDomains(r.ReconciliationSubject.Spec.FailureDomains),

controllers/cloudstackfailuredomain_controller.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ package controllers
1919
import (
2020
"context"
2121

22+
"github.com/onsi/ginkgo/v2"
23+
24+
"github.com/pkg/errors"
25+
corev1 "k8s.io/api/core/v1"
2226
ctrl "sigs.k8s.io/controller-runtime"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2328

2429
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
2530
csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
@@ -54,6 +59,7 @@ func NewCSFailureDomainReconciliationRunner() *CloudStackFailureDomainReconcilia
5459

5560
// Reconcile is the method k8s will call upon a reconciliation request.
5661
func (reconciler *CloudStackFailureDomainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (retRes ctrl.Result, retErr error) {
62+
defer ginkgo.GinkgoRecover()
5763
return NewCSFailureDomainReconciliationRunner().
5864
UsingBaseReconciler(reconciler.ReconcilerBase).
5965
ForRequest(req).
@@ -63,7 +69,45 @@ func (reconciler *CloudStackFailureDomainReconciler) Reconcile(ctx context.Conte
6369

6470
// Reconcile on the ReconciliationRunner actually attempts to modify or create the reconciliation subject.
6571
func (r *CloudStackFailureDomainReconciliationRunner) Reconcile() (retRes ctrl.Result, retErr error) {
66-
r.Log.Info("blah2")
72+
defer ginkgo.GinkgoRecover()
73+
endpointCredentials := &corev1.Secret{}
74+
ref := r.ReconciliationSubject.Spec.ACSEndpoint
75+
key := client.ObjectKey{Name: ref.Name, Namespace: ref.Namespace}
76+
if err := r.K8sClient.Get(r.RequestCtx, key, endpointCredentials); err != nil {
77+
return ctrl.Result{}, errors.Wrapf(err, "getting ACSEndpoint secret with ref: %v", ref)
78+
}
79+
// Prevent premature deletion.
80+
controllerutil.AddFinalizer(r.ReconciliationSubject, infrav1.)
81+
82+
// Start by purely data fetching information about the zone and specified network.
83+
if err := r.CSUser.ResolveZone(r.ReconciliationSubject); err != nil {
84+
return ctrl.Result{}, errors.Wrap(err, "resolving CloudStack zone information")
85+
}
86+
if err := r.CSUser.ResolveNetworkForZone(r.ReconciliationSubject); err != nil &&
87+
!csCtrlrUtils.ContainsNoMatchSubstring(err) {
88+
return ctrl.Result{}, errors.Wrap(err, "resolving Cloudstack network information")
89+
}
90+
91+
// Address Isolated Networks.
92+
// Check if the passed network was an isolated network or the network was missing. In either case, create a
93+
// CloudStackIsolatedNetwork to manage the many intricacies and wait until CloudStackIsolatedNetwork is ready.
94+
if r.ReconciliationSubject.Spec.Network.ID == "" || r.ReconciliationSubject.Spec.Network.Type == infrav1.NetworkTypeIsolated {
95+
netName := r.ReconciliationSubject.Spec.Network.Name
96+
if res, err := r.GenerateIsolatedNetwork(netName)(); r.ShouldReturn(res, err) {
97+
return res, err
98+
} else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
99+
return res, err
100+
}
101+
if r.IsoNet.Name == "" {
102+
return r.RequeueWithMessage("Couldn't find isolated network.")
103+
}
104+
if !r.IsoNet.Status.Ready {
105+
return r.RequeueWithMessage("Isolated network dependency not ready.")
106+
}
107+
}
108+
r.ReconciliationSubject.Status.Ready = true
109+
return ctrl.Result{}, nil
110+
}
67111
r.ReconciliationSubject.Status.Ready = true
68112
return ctrl.Result{}, nil
69113
}

controllers/cloudstackfailuredomain_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var _ = Describe("CloudStackFailureDomainReconciler", func() {
3333
})
3434

3535
It("Should set failure domain Status.Ready to true.", func() {
36+
Ω(k8sClient.Create(ctx, dummies.ACSEndpointSecret1))
3637
Ω(k8sClient.Create(ctx, dummies.CSFailureDomain1))
3738

3839
tempfd := &infrav1.CloudStackFailureDomain{}

controllers/cloudstackisolatednetwork_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"github.com/onsi/ginkgo/v2"
2122
"strings"
2223

2324
"sigs.k8s.io/cluster-api/util/patch"
@@ -57,6 +58,7 @@ func NewCSIsoNetReconciliationRunner() *CloudStackIsoNetReconciliationRunner {
5758
}
5859

5960
func (reconciler *CloudStackIsoNetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, retErr error) {
61+
defer ginkgo.GinkgoRecover()
6062
return NewCSIsoNetReconciliationRunner().
6163
UsingBaseReconciler(reconciler.ReconcilerBase).
6264
ForRequest(req).
@@ -65,6 +67,7 @@ func (reconciler *CloudStackIsoNetReconciler) Reconcile(ctx context.Context, req
6567
}
6668

6769
func (r *CloudStackIsoNetReconciliationRunner) Reconcile() (retRes ctrl.Result, retErr error) {
70+
defer ginkgo.GinkgoRecover()
6871
if res, err := r.RequeueIfMissingBaseCRs(); r.ShouldReturn(res, err) {
6972
return res, err
7073
}

controllers/cloudstackmachine_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"github.com/onsi/ginkgo/v2"
2223
"math/rand"
2324
"reflect"
2425

@@ -81,6 +82,7 @@ func NewCSMachineReconciliationRunner() *CloudStackMachineReconciliationRunner {
8182
// Reconcile is part of the main kubernetes reconciliation loop which aims to
8283
// move the current state of the cluster closer to the desired state.
8384
func (reconciler *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, retErr error) {
85+
defer ginkgo.GinkgoRecover()
8486
return NewCSMachineReconciliationRunner().
8587
UsingBaseReconciler(reconciler.ReconcilerBase).
8688
ForRequest(req).
@@ -89,6 +91,7 @@ func (reconciler *CloudStackMachineReconciler) Reconcile(ctx context.Context, re
8991
}
9092

9193
func (r *CloudStackMachineReconciliationRunner) Reconcile() (retRes ctrl.Result, reterr error) {
94+
defer ginkgo.GinkgoRecover()
9295
return r.RunReconciliationStages(
9396
r.GetZonesAndRequeueIfMissing(r.Zones),
9497
r.GetParent(r.ReconciliationSubject, r.CAPIMachine),

0 commit comments

Comments
 (0)