Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes tls certificate issue for webhook endpoint #1120

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,18 @@ func main() {
}

ctx := context.Background()
var caContent []byte
operatorCATLSCert, err := kubeClient.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(ctx, "operator-ca-tls", metav1.GetOptions{})
// if custom ca.crt is not present in kubernetes secrets use the one stored in the pod
if err != nil {
caContent = miniov2.GetPodCAFromFile()
} else {

// Default kubernetes CA certificate
caContent := miniov2.GetPodCAFromFile()
// custom ca certificate to be used by operator
operatorCATLSCert, err := kubeClient.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(ctx, cluster.OperatorTLSCASecretName, metav1.GetOptions{})
if err == nil && operatorCATLSCert != nil {
if val, ok := operatorCATLSCert.Data["ca.crt"]; ok {
caContent = val
caContent = append(caContent, val...)
} else if val, ok = operatorCATLSCert.Data["public.crt"]; ok {
caContent = append(caContent, val...)
}
}

if len(caContent) > 0 {
crd, err := extClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), "tenants.minio.min.io", metav1.GetOptions{})
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/controller/cluster/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,20 @@ func (c *Controller) getTransport() *http.Transport {
if c.transport != nil {
return c.transport
}

rootCAs := miniov2.MustGetSystemCertPool()
// Default kubernetes CA certificate
rootCAs.AppendCertsFromPEM(miniov2.GetPodCAFromFile())
var caContent []byte
// Custom ca certificate to be used by operator
operatorCATLSCert, err := c.kubeClientSet.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(context.Background(), OperatorTLSCASecretName, metav1.GetOptions{})
// if custom ca.crt is not present in kubernetes secrets use the one stored in the pod
if err != nil {
caContent = miniov2.GetPodCAFromFile()
} else {
if err == nil && operatorCATLSCert != nil {
if val, ok := operatorCATLSCert.Data["ca.crt"]; ok {
caContent = val
} else if val, ok = operatorCATLSCert.Data["public.crt"]; ok {
caContent = val
}
}

rootCAs := miniov2.MustGetSystemCertPool()
if len(caContent) > 0 {
rootCAs.AppendCertsFromPEM(caContent)
}
Expand Down