Skip to content

Commit

Permalink
add newlines between certs
Browse files Browse the repository at this point in the history
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
  • Loading branch information
HumairAK committed Aug 13, 2024
1 parent 94eb6c6 commit 1f1ec42
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions controllers/dspipeline_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (p *DSPAParams) ExtractParams(ctx context.Context, dsp *dspa.DataSciencePip
for _, val := range globalCerts {
// If the ca-bundle field is empty, ignore it
if val != "" {
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(val))
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(val), []byte("\n"))
}
}
// If odh-trusted-ca-bundle is created via network operator then this is always going to be present
Expand All @@ -721,7 +721,7 @@ func (p *DSPAParams) ExtractParams(ctx context.Context, dsp *dspa.DataSciencePip
dspaProvidedCABundle := util.GetConfigMapValue(dspaCaBundleCfgKey, dspaCAConfigMap)
// If the ca-bundle field is empty, ignore it
if dspaProvidedCABundle != "" {
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(dspaProvidedCABundle))
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(dspaProvidedCABundle), []byte("\n"))
}
}

Expand All @@ -738,7 +738,7 @@ func (p *DSPAParams) ExtractParams(ctx context.Context, dsp *dspa.DataSciencePip
if serviceCABundle == "" {
return fmt.Errorf("expected key %s from configmap %s not found", config.OpenshiftServiceCAConfigMapKey, config.OpenshiftServiceCAConfigMapName)
}
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(serviceCABundle))
p.APICustomPemCerts = append(p.APICustomPemCerts, []byte(serviceCABundle), []byte("\n"))
}

if p.APIServer.CABundleFileMountPath != "" {
Expand Down Expand Up @@ -771,7 +771,7 @@ func (p *DSPAParams) ExtractParams(ctx context.Context, dsp *dspa.DataSciencePip
}

if len(certs) != 0 {
p.APICustomPemCerts = append(p.APICustomPemCerts, certs)
p.APICustomPemCerts = append(p.APICustomPemCerts, certs, []byte("\n"))
}
}

Expand Down
14 changes: 7 additions & 7 deletions controllers/dspipeline_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("bundle-contents")},
APICustomPemCerts: [][]byte{[]byte("bundle-contents"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand All @@ -98,7 +98,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents")},
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand All @@ -113,7 +113,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents-2")},
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents-2"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents"), []byte("bundle-contents")},
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents"), []byte("\n"), []byte("bundle-contents"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand All @@ -162,7 +162,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents"), []byte("bundle-contents"), []byte("dummycontent")},
APICustomPemCerts: [][]byte{[]byte("odh-bundle-contents"), []byte("\n"), []byte("bundle-contents"), []byte("\n"), []byte("dummycontent"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand All @@ -183,7 +183,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("service-ca-contents")},
APICustomPemCerts: [][]byte{[]byte("service-ca-contents"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand All @@ -198,7 +198,7 @@ func TestExtractParams_CABundle(t *testing.T) {
CustomCABundleRootMountPath: "/dsp-custom-certs",
CustomSSLCertDir: strPtr("/dsp-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs"),
PiplinesCABundleMountPath: "/dsp-custom-certs/dsp-ca.crt",
APICustomPemCerts: [][]byte{[]byte("service-ca-contents"), []byte("dummycontent")},
APICustomPemCerts: [][]byte{[]byte("service-ca-contents"), []byte("\n"), []byte("dummycontent"), []byte("\n")},
CustomCABundle: &dspav1alpha1.CABundle{ConfigMapKey: "dsp-ca.crt", ConfigMapName: "dsp-trusted-ca-testdspa"},
ConfigMapPreReq: []*v1.ConfigMap{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data:
WBV3KJBsYK/wijtLeip1oKobU76oE0ML/bnhV10k6usvl4n8cDmcONo5FnGoT8Pk
80htx6w5fanMFu4MnoBeyJhhzNfg7ywJcc2VZSM27s2B
-----END CERTIFICATE-----
odh-ca-bundle.crt: |
-----BEGIN CERTIFICATE-----
MIIFLTCCAxWgAwIBAgIUIvY4jV0212P/ddjuCZhcUyJfoocwDQYJKoZIhvcNAQEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data:
WBV3KJBsYK/wijtLeip1oKobU76oE0ML/bnhV10k6usvl4n8cDmcONo5FnGoT8Pk
80htx6w5fanMFu4MnoBeyJhhzNfg7ywJcc2VZSM27s2B
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFLTCCAxWgAwIBAgIUIvY4jV0212P/ddjuCZhcUyJfoocwDQYJKoZIhvcNAQEL
BQAwJjELMAkGA1UEBhMCWFgxFzAVBgNVBAMMDnJoLWRzcC1kZXZzLmlvMB4XDTI0
Expand Down Expand Up @@ -64,6 +65,7 @@ data:
WBV3KJBsYK/wijtLeip1oKobU76oE0ML/bnhV10k6usvl4n8cDmcONo5FnGoT8Pk
80htx6w5fanMFu4MnoBeyJhhzNfg7ywJcc2VZSM27s2B
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFlTCCA32gAwIBAgIUQTPwwkR17jDrdIe4VqhzNQ6OY1MwDQYJKoZIhvcNAQEL
BQAwJjELMAkGA1UEBhMCWFgxFzAVBgNVBAMMDnJoLWRzcC1kZXZzLmlvMB4XDTI0
Expand Down Expand Up @@ -96,6 +98,7 @@ data:
lsiMw+o9r32W0fzjQRwipTLNM0lEbgWyErsVXFb67vY/rjy9ybuFlKMMOIlZpmut
wcr1vUGA985Lhv2jire2GTlixOiqZtuQS08lGa7kkcO8sB+7MdRdgEI=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFLTCCAxWgAwIBAgIUIvY4jV0212P/ddjuCZhcUyJfoocwDQYJKoZIhvcNAQEL
BQAwJjELMAkGA1UEBhMCWFgxFzAVBgNVBAMMDnJoLWRzcC1kZXZzLmlvMB4XDTI0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data:
WBV3KJBsYK/wijtLeip1oKobU76oE0ML/bnhV10k6usvl4n8cDmcONo5FnGoT8Pk
80htx6w5fanMFu4MnoBeyJhhzNfg7ywJcc2VZSM27s2B
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFLTCCAxWgAwIBAgIUIvY4jV0212P/ddjuCZhcUyJfoocwDQYJKoZIhvcNAQEL
BQAwJjELMAkGA1UEBhMCWFgxFzAVBgNVBAMMDnJoLWRzcC1kZXZzLmlvMB4XDTI0
Expand Down Expand Up @@ -64,6 +65,7 @@ data:
WBV3KJBsYK/wijtLeip1oKobU76oE0ML/bnhV10k6usvl4n8cDmcONo5FnGoT8Pk
80htx6w5fanMFu4MnoBeyJhhzNfg7ywJcc2VZSM27s2B
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFLTCCAxWgAwIBAgIUIvY4jV0212P/ddjuCZhcUyJfoocwDQYJKoZIhvcNAQEL
BQAwJjELMAkGA1UEBhMCWFgxFzAVBgNVBAMMDnJoLWRzcC1kZXZzLmlvMB4XDTI0
Expand Down
11 changes: 11 additions & 0 deletions controllers/testutil/equalities.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package testutil

import (
"fmt"
"strings"

"github.com/go-test/deep"

Expand Down Expand Up @@ -52,6 +53,16 @@ func configMapsAreEqual(expected, actual *unstructured.Unstructured) (bool, erro
return false, notEqualMsg("Configmap Names are not equal.")
}

// Functional tests are very buggy when it comes to accounting for trailing white spaces and can be hard to
// diagnose, we trim these so we are only comparing the core contents, to account for whitespace testing
// defer to unit testing
for k := range expectedConfigMap.Data {
expectedConfigMap.Data[k] = strings.TrimSpace(expectedConfigMap.Data[k])
}
for k := range actualConfigMap.Data {
actualConfigMap.Data[k] = strings.TrimSpace(actualConfigMap.Data[k])
}

diff := deep.Equal(expectedConfigMap.Data, actualConfigMap.Data)
if diff != nil {
return false, notDeeplyEqualMsg("Configmap's Data values", diff)
Expand Down

0 comments on commit 1f1ec42

Please sign in to comment.