Skip to content

Commit 9b0b603

Browse files
committed
Make restTLSClientConfig in restConfig a public field
imdario/mergo, despite its official documentation, does not merge public fields inside private fields as of v.0.3.9: darccio/mergo#139 Fixing that seems non-trivial. Instead, make the restTLSClientConfig a public field of restConfig. The restConfig type itself remains private, so this does not make anything actually public outside the subpackage. This way, the calls to mergo work as expected with both 0.3.8 and 0.3.9. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent bf134c3 commit 9b0b603

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

openshift/openshift-copies.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type restConfig struct {
6565
BearerToken string
6666

6767
// TLSClientConfig contains settings to enable transport layer security
68-
restTLSClientConfig
68+
TLSClientConfig restTLSClientConfig
6969

7070
// Server should be accessed without verifying the TLS
7171
// certificate. For testing only.
@@ -238,8 +238,8 @@ func getServerIdentificationPartialConfig(configAuthInfo clientcmdAuthInfo, conf
238238

239239
// configClusterInfo holds the information identify the server provided by .kubeconfig
240240
configClientConfig := &restConfig{}
241-
configClientConfig.CAFile = configClusterInfo.CertificateAuthority
242-
configClientConfig.CAData = configClusterInfo.CertificateAuthorityData
241+
configClientConfig.TLSClientConfig.CAFile = configClusterInfo.CertificateAuthority
242+
configClientConfig.TLSClientConfig.CAData = configClusterInfo.CertificateAuthorityData
243243
configClientConfig.Insecure = configClusterInfo.InsecureSkipTLSVerify
244244
if err := mergo.MergeWithOverwrite(mergedConfig, configClientConfig); err != nil {
245245
return nil, err
@@ -264,10 +264,10 @@ func getUserIdentificationPartialConfig(configAuthInfo clientcmdAuthInfo) (*rest
264264
mergedConfig.BearerToken = configAuthInfo.Token
265265
}
266266
if len(configAuthInfo.ClientCertificate) > 0 || len(configAuthInfo.ClientCertificateData) > 0 {
267-
mergedConfig.CertFile = configAuthInfo.ClientCertificate
268-
mergedConfig.CertData = configAuthInfo.ClientCertificateData
269-
mergedConfig.KeyFile = configAuthInfo.ClientKey
270-
mergedConfig.KeyData = configAuthInfo.ClientKeyData
267+
mergedConfig.TLSClientConfig.CertFile = configAuthInfo.ClientCertificate
268+
mergedConfig.TLSClientConfig.CertData = configAuthInfo.ClientCertificateData
269+
mergedConfig.TLSClientConfig.KeyFile = configAuthInfo.ClientKey
270+
mergedConfig.TLSClientConfig.KeyData = configAuthInfo.ClientKeyData
271271
}
272272
if len(configAuthInfo.Username) > 0 || len(configAuthInfo.Password) > 0 {
273273
mergedConfig.Username = configAuthInfo.Username
@@ -806,8 +806,8 @@ func defaultServerURL(host string, defaultTLS bool) (*url.URL, error) {
806806
func defaultServerURLFor(config *restConfig) (*url.URL, error) {
807807
// TODO: move the default to secure when the apiserver supports TLS by default
808808
// config.Insecure is taken to mean "I want HTTPS but don't bother checking the certs against a CA."
809-
hasCA := len(config.CAFile) != 0 || len(config.CAData) != 0
810-
hasCert := len(config.CertFile) != 0 || len(config.CertData) != 0
809+
hasCA := len(config.TLSClientConfig.CAFile) != 0 || len(config.TLSClientConfig.CAData) != 0
810+
hasCert := len(config.TLSClientConfig.CertFile) != 0 || len(config.TLSClientConfig.CertData) != 0
811811
defaultTLS := hasCA || hasCert || config.Insecure
812812
host := config.Host
813813
if host == "" {
@@ -968,11 +968,11 @@ func tlsConfigFor(c *restConfig) (*tls.Config, error) {
968968
}
969969

970970
if c.HasCA() {
971-
tlsConfig.RootCAs = rootCertPool(c.CAData)
971+
tlsConfig.RootCAs = rootCertPool(c.TLSClientConfig.CAData)
972972
}
973973

974974
if c.HasCertAuth() {
975-
cert, err := tls.X509KeyPair(c.CertData, c.KeyData)
975+
cert, err := tls.X509KeyPair(c.TLSClientConfig.CertData, c.TLSClientConfig.KeyData)
976976
if err != nil {
977977
return nil, err
978978
}
@@ -988,17 +988,17 @@ func tlsConfigFor(c *restConfig) (*tls.Config, error) {
988988
// either populated or were empty to start.
989989
func loadTLSFiles(c *restConfig) error {
990990
var err error
991-
c.CAData, err = dataFromSliceOrFile(c.CAData, c.CAFile)
991+
c.TLSClientConfig.CAData, err = dataFromSliceOrFile(c.TLSClientConfig.CAData, c.TLSClientConfig.CAFile)
992992
if err != nil {
993993
return err
994994
}
995995

996-
c.CertData, err = dataFromSliceOrFile(c.CertData, c.CertFile)
996+
c.TLSClientConfig.CertData, err = dataFromSliceOrFile(c.TLSClientConfig.CertData, c.TLSClientConfig.CertFile)
997997
if err != nil {
998998
return err
999999
}
10001000

1001-
c.KeyData, err = dataFromSliceOrFile(c.KeyData, c.KeyFile)
1001+
c.TLSClientConfig.KeyData, err = dataFromSliceOrFile(c.TLSClientConfig.KeyData, c.TLSClientConfig.KeyFile)
10021002
if err != nil {
10031003
return err
10041004
}
@@ -1042,13 +1042,13 @@ func rootCertPool(caData []byte) *x509.CertPool {
10421042
// HasCA is a modified copy of k8s.io/kubernetes/pkg/client/transport.Config.HasCA.
10431043
// HasCA returns whether the configuration has a certificate authority or not.
10441044
func (c *restConfig) HasCA() bool {
1045-
return len(c.CAData) > 0 || len(c.CAFile) > 0
1045+
return len(c.TLSClientConfig.CAData) > 0 || len(c.TLSClientConfig.CAFile) > 0
10461046
}
10471047

10481048
// HasCertAuth is a modified copy of k8s.io/kubernetes/pkg/client/transport.Config.HasCertAuth.
10491049
// HasCertAuth returns whether the configuration has certificate authentication or not.
10501050
func (c *restConfig) HasCertAuth() bool {
1051-
return len(c.CertData) != 0 || len(c.CertFile) != 0
1051+
return len(c.TLSClientConfig.CertData) != 0 || len(c.TLSClientConfig.CertFile) != 0
10521052
}
10531053

10541054
// clientcmdConfig is a modified copy of k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api.Config.

openshift/openshift-copies_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestDirectClientConfig(t *testing.T) {
7878
require.NoError(t, err)
7979
assert.Equal(t, &restConfig{
8080
Host: "https://172.17.0.2:8443",
81-
restTLSClientConfig: restTLSClientConfig{
81+
TLSClientConfig: restTLSClientConfig{
8282
CertData: []byte("Client cert"),
8383
KeyData: []byte("Client key"),
8484
CAData: []byte("Cluster CA"),
@@ -96,7 +96,7 @@ func TestDeferredLoadingClientConfig(t *testing.T) {
9696
require.NoError(t, err)
9797
assert.Equal(t, &restConfig{
9898
Host: "https://172.17.0.2:8443",
99-
restTLSClientConfig: restTLSClientConfig{
99+
TLSClientConfig: restTLSClientConfig{
100100
CertData: []byte("Client cert"),
101101
KeyData: []byte("Client key"),
102102
CAData: []byte("Cluster CA"),
@@ -113,7 +113,7 @@ func TestDefaultClientConfig(t *testing.T) {
113113
require.NoError(t, err)
114114
assert.Equal(t, &restConfig{
115115
Host: "https://172.17.0.2:8443",
116-
restTLSClientConfig: restTLSClientConfig{
116+
TLSClientConfig: restTLSClientConfig{
117117
CertData: []byte("Client cert"),
118118
KeyData: []byte("Client key"),
119119
CAData: []byte("Cluster CA"),

0 commit comments

Comments
 (0)