Skip to content

Commit b69c290

Browse files
authored
CNV-74932: Set the TLSSecurityProfile field in AAQ CR (#4037)
Signed-off-by: Nahshon Unna Tsameret <nunnatsa@redhat.com>
1 parent 346f355 commit b69c290

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

controllers/handlers/aaq.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66
"sync"
77

8+
openshiftconfigv1 "github.com/openshift/api/config/v1"
89
corev1 "k8s.io/api/core/v1"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/runtime"
@@ -17,6 +18,7 @@ import (
1718
"github.com/kubevirt/hyperconverged-cluster-operator/controllers/common"
1819
"github.com/kubevirt/hyperconverged-cluster-operator/controllers/operands"
1920
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/reformatobj"
21+
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/tlssecprofile"
2022
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
2123
)
2224

@@ -110,6 +112,7 @@ func NewAAQ(hc *hcov1beta1.HyperConverged) (*aaqv1alpha1.AAQ, error) {
110112
RenewBefore: hc.Spec.CertConfig.Server.RenewBefore,
111113
},
112114
},
115+
TLSSecurityProfile: openshift2AAQSecProfile(tlssecprofile.GetTLSSecurityProfile(hc.Spec.TLSSecurityProfile)),
113116
}
114117

115118
if hc.Spec.Infra.NodePlacement != nil {
@@ -147,3 +150,23 @@ func NewAAQWithNameOnly(hc *hcov1beta1.HyperConverged) *aaqv1alpha1.AAQ {
147150
},
148151
}
149152
}
153+
154+
func openshift2AAQSecProfile(hcProfile *openshiftconfigv1.TLSSecurityProfile) *aaqv1alpha1.TLSSecurityProfile {
155+
var custom *aaqv1alpha1.CustomTLSProfile
156+
if hcProfile.Custom != nil {
157+
custom = &aaqv1alpha1.CustomTLSProfile{
158+
TLSProfileSpec: aaqv1alpha1.TLSProfileSpec{
159+
Ciphers: hcProfile.Custom.Ciphers,
160+
MinTLSVersion: aaqv1alpha1.TLSProtocolVersion(hcProfile.Custom.MinTLSVersion),
161+
},
162+
}
163+
}
164+
165+
return &aaqv1alpha1.TLSSecurityProfile{
166+
Type: aaqv1alpha1.TLSProfileType(hcProfile.Type),
167+
Old: (*aaqv1alpha1.OldTLSProfile)(hcProfile.Old),
168+
Intermediate: (*aaqv1alpha1.IntermediateTLSProfile)(hcProfile.Intermediate),
169+
Modern: (*aaqv1alpha1.ModernTLSProfile)(hcProfile.Modern),
170+
Custom: custom,
171+
}
172+
}

controllers/handlers/aaq_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
. "github.com/onsi/ginkgo/v2"
99
. "github.com/onsi/gomega"
10+
openshiftconfigv1 "github.com/openshift/api/config/v1"
1011
corev1 "k8s.io/api/core/v1"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
"k8s.io/apimachinery/pkg/types"
@@ -163,6 +164,80 @@ var _ = Describe("AAQ tests", func() {
163164
Expect(aaq.Spec.CertConfig.Server.Duration.Duration.String()).To(Equal("36h0m0s"))
164165
Expect(aaq.Spec.CertConfig.Server.RenewBefore.Duration.String()).To(Equal("18h0m0s"))
165166
})
167+
168+
Context("TLSSecurityProfile", func() {
169+
170+
intermediateTLSSecurityProfile := &openshiftconfigv1.TLSSecurityProfile{
171+
Type: openshiftconfigv1.TLSProfileIntermediateType,
172+
Intermediate: &openshiftconfigv1.IntermediateTLSProfile{},
173+
}
174+
modernTLSSecurityProfile := &openshiftconfigv1.TLSSecurityProfile{
175+
Type: openshiftconfigv1.TLSProfileModernType,
176+
Modern: &openshiftconfigv1.ModernTLSProfile{},
177+
}
178+
179+
It("should modify TLSSecurityProfile on AAQ CR according to ApiServer or HCO CR", func(ctx context.Context) {
180+
existingResource, err := NewAAQ(hco)
181+
Expect(err).ToNot(HaveOccurred())
182+
Expect(existingResource.Spec.TLSSecurityProfile).To(Equal(openshift2AAQSecProfile(intermediateTLSSecurityProfile)))
183+
184+
// now, modify HCO's TLSSecurityProfile
185+
hco.Spec.TLSSecurityProfile = modernTLSSecurityProfile
186+
hco.Spec.EnableApplicationAwareQuota = ptr.To(true)
187+
188+
cl := commontestutils.InitClient([]client.Object{hco, existingResource})
189+
handler := NewAAQHandler(cl, commontestutils.GetScheme())
190+
res := handler.Ensure(req)
191+
Expect(res.UpgradeDone).To(BeFalse())
192+
Expect(res.Updated).To(BeTrue())
193+
Expect(res.Err).ToNot(HaveOccurred())
194+
195+
foundResource := &aaqv1alpha1.AAQ{}
196+
Expect(
197+
cl.Get(ctx,
198+
types.NamespacedName{Name: existingResource.Name, Namespace: existingResource.Namespace},
199+
foundResource),
200+
).ToNot(HaveOccurred())
201+
202+
Expect(foundResource.Spec.TLSSecurityProfile).To(Equal(openshift2AAQSecProfile(modernTLSSecurityProfile)))
203+
204+
Expect(req.Conditions).To(BeEmpty())
205+
})
206+
207+
It("should overwrite TLSSecurityProfile if directly set on AAQ CR", func(ctx context.Context) {
208+
hco.Spec.TLSSecurityProfile = intermediateTLSSecurityProfile
209+
existingResource, err := NewAAQ(hco)
210+
Expect(err).ToNot(HaveOccurred())
211+
212+
// mock a reconciliation triggered by a change in AAQ CR
213+
req.HCOTriggered = false
214+
215+
// now, modify AAQ node placement
216+
existingResource.Spec.TLSSecurityProfile = openshift2AAQSecProfile(modernTLSSecurityProfile)
217+
218+
hco.Spec.EnableApplicationAwareQuota = ptr.To(true)
219+
220+
cl := commontestutils.InitClient([]client.Object{hco, existingResource})
221+
handler := NewAAQHandler(cl, commontestutils.GetScheme())
222+
res := handler.Ensure(req)
223+
Expect(res.UpgradeDone).To(BeFalse())
224+
Expect(res.Updated).To(BeTrue())
225+
Expect(res.Overwritten).To(BeTrue())
226+
Expect(res.Err).ToNot(HaveOccurred())
227+
228+
foundResource := &aaqv1alpha1.AAQ{}
229+
Expect(
230+
cl.Get(ctx,
231+
types.NamespacedName{Name: existingResource.Name, Namespace: existingResource.Namespace},
232+
foundResource),
233+
).ToNot(HaveOccurred())
234+
235+
Expect(foundResource.Spec.TLSSecurityProfile).To(Equal(openshift2AAQSecProfile(hco.Spec.TLSSecurityProfile)))
236+
Expect(foundResource.Spec.TLSSecurityProfile).ToNot(Equal(existingResource.Spec.TLSSecurityProfile))
237+
238+
Expect(req.Conditions).To(BeEmpty())
239+
})
240+
})
166241
})
167242

168243
Context("check FG", func() {

0 commit comments

Comments
 (0)