Skip to content

Commit

Permalink
convert openshift TLSSecurityProfile to the CDI type
Browse files Browse the repository at this point in the history
CDI new API redefined the TLSSecurityProfile type, originally from
openshift. These two types are identicle, but each sub-type is
redefined, and so each field requires castings.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
  • Loading branch information
nunnatsa committed Aug 19, 2024
1 parent b2066ad commit 4da4456
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
24 changes: 22 additions & 2 deletions controllers/hyperconverged/hyperconverged_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ var _ = Describe("HyperconvergedController", func() {
cdi),
).To(Succeed())

Expect(cdi.Spec.Config.TLSSecurityProfile).To(Equal(initialTLSSecurityProfile))
Expect(cdi.Spec.Config.TLSSecurityProfile).To(Equal(openshift2CdiSecProfile(initialTLSSecurityProfile)))

})
By("Verify that CNA was properly configured with initialTLSSecurityProfile", func() {
Expand Down Expand Up @@ -1265,7 +1265,7 @@ var _ = Describe("HyperconvergedController", func() {
cdi),
).To(Succeed())

Expect(cdi.Spec.Config.TLSSecurityProfile).To(Equal(customTLSSecurityProfile))
Expect(cdi.Spec.Config.TLSSecurityProfile).To(Equal(openshift2CdiSecProfile(customTLSSecurityProfile)))

})
By("Verify that CNA was properly updated with customTLSSecurityProfile", func() {
Expand Down Expand Up @@ -3911,3 +3911,23 @@ func searchInRelatedObjects(relatedObjects []corev1.ObjectReference, kind, name
}
return false
}

func openshift2CdiSecProfile(hcProfile *openshiftconfigv1.TLSSecurityProfile) *cdiv1beta1.TLSSecurityProfile {
var custom *cdiv1beta1.CustomTLSProfile
if hcProfile.Custom != nil {
custom = &cdiv1beta1.CustomTLSProfile{
TLSProfileSpec: cdiv1beta1.TLSProfileSpec{
Ciphers: hcProfile.Custom.TLSProfileSpec.Ciphers,
MinTLSVersion: cdiv1beta1.TLSProtocolVersion(hcProfile.Custom.TLSProfileSpec.MinTLSVersion),
},
}
}

return &cdiv1beta1.TLSSecurityProfile{
Type: cdiv1beta1.TLSProfileType(hcProfile.Type),
Old: (*cdiv1beta1.OldTLSProfile)(hcProfile.Old),
Intermediate: (*cdiv1beta1.IntermediateTLSProfile)(hcProfile.Intermediate),
Modern: (*cdiv1beta1.ModernTLSProfile)(hcProfile.Modern),
Custom: custom,
}
}
23 changes: 22 additions & 1 deletion controllers/operands/cdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"reflect"

openshiftconfigv1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -104,7 +105,7 @@ func NewCDI(hc *hcov1beta1.HyperConverged, opts ...string) (*cdiv1beta1.CDI, err
UninstallStrategy: &uninstallStrategy,
Config: &cdiv1beta1.CDIConfigSpec{
FeatureGates: getDefaultFeatureGates(),
TLSSecurityProfile: hcoutil.GetClusterInfo().GetTLSSecurityProfile(hc.Spec.TLSSecurityProfile),
TLSSecurityProfile: openshift2CdiSecProfile(hcoutil.GetClusterInfo().GetTLSSecurityProfile(hc.Spec.TLSSecurityProfile)),
},
CertConfig: &cdiv1beta1.CDICertConfig{
CA: &cdiv1beta1.CertConfig{
Expand Down Expand Up @@ -169,3 +170,23 @@ func NewCDIWithNameOnly(hc *hcov1beta1.HyperConverged, opts ...string) *cdiv1bet
},
}
}

func openshift2CdiSecProfile(hcProfile *openshiftconfigv1.TLSSecurityProfile) *cdiv1beta1.TLSSecurityProfile {
var custom *cdiv1beta1.CustomTLSProfile
if hcProfile.Custom != nil {
custom = &cdiv1beta1.CustomTLSProfile{
TLSProfileSpec: cdiv1beta1.TLSProfileSpec{
Ciphers: hcProfile.Custom.TLSProfileSpec.Ciphers,
MinTLSVersion: cdiv1beta1.TLSProtocolVersion(hcProfile.Custom.TLSProfileSpec.MinTLSVersion),
},
}
}

return &cdiv1beta1.TLSSecurityProfile{
Type: cdiv1beta1.TLSProfileType(hcProfile.Type),
Old: (*cdiv1beta1.OldTLSProfile)(hcProfile.Old),
Intermediate: (*cdiv1beta1.IntermediateTLSProfile)(hcProfile.Intermediate),
Modern: (*cdiv1beta1.ModernTLSProfile)(hcProfile.Modern),
Custom: custom,
}
}
8 changes: 4 additions & 4 deletions controllers/operands/cdi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ var _ = Describe("CDI Operand", func() {
It("should modify TLSSecurityProfile on CDI CR according to ApiServer or HCO CR", func() {
existingResource, err := NewCDI(hco)
Expect(err).ToNot(HaveOccurred())
Expect(existingResource.Spec.Config.TLSSecurityProfile).To(Equal(intermediateTLSSecurityProfile))
Expect(existingResource.Spec.Config.TLSSecurityProfile).To(Equal(openshift2CdiSecProfile(intermediateTLSSecurityProfile)))

// now, modify HCO's TLSSecurityProfile
hco.Spec.TLSSecurityProfile = modernTLSSecurityProfile
Expand All @@ -1342,7 +1342,7 @@ var _ = Describe("CDI Operand", func() {
foundResource),
).ToNot(HaveOccurred())

Expect(foundResource.Spec.Config.TLSSecurityProfile).To(Equal(modernTLSSecurityProfile))
Expect(foundResource.Spec.Config.TLSSecurityProfile).To(Equal(openshift2CdiSecProfile(modernTLSSecurityProfile)))

Expect(req.Conditions).To(BeEmpty())
})
Expand All @@ -1356,7 +1356,7 @@ var _ = Describe("CDI Operand", func() {
req.HCOTriggered = false

// now, modify CDI node placement
existingResource.Spec.Config.TLSSecurityProfile = modernTLSSecurityProfile
existingResource.Spec.Config.TLSSecurityProfile = openshift2CdiSecProfile(modernTLSSecurityProfile)

cl := commontestutils.InitClient([]client.Object{hco, existingResource})
handler := (*genericOperand)(newCdiHandler(cl, commontestutils.GetScheme()))
Expand All @@ -1373,7 +1373,7 @@ var _ = Describe("CDI Operand", func() {
foundResource),
).ToNot(HaveOccurred())

Expect(foundResource.Spec.Config.TLSSecurityProfile).To(Equal(hco.Spec.TLSSecurityProfile))
Expect(foundResource.Spec.Config.TLSSecurityProfile).To(Equal(openshift2CdiSecProfile(hco.Spec.TLSSecurityProfile)))
Expect(foundResource.Spec.Config.TLSSecurityProfile).ToNot(Equal(existingResource.Spec.Config.TLSSecurityProfile))

Expect(req.Conditions).To(BeEmpty())
Expand Down

0 comments on commit 4da4456

Please sign in to comment.