@@ -19,12 +19,6 @@ package controller
19
19
import (
20
20
"context"
21
21
"errors"
22
- "strings"
23
-
24
- "github.com/minio/operator/pkg/certs"
25
-
26
- corev1 "k8s.io/api/core/v1"
27
- "k8s.io/klog/v2"
28
22
29
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
24
@@ -51,93 +45,6 @@ func (c *Controller) getTenantConfiguration(ctx context.Context, tenant *miniov2
51
45
return tenantConfiguration , nil
52
46
}
53
47
54
- // renewCert will renew one certificate at a time
55
- func (c * Controller ) renewCert (secret corev1.Secret , index int , tenant * miniov2.Tenant ) error {
56
- // If the secret does not start with "operator-ca-tls-" then no need to continue
57
- if ! strings .HasPrefix (secret .Name , OperatorCATLSSecretPrefix ) {
58
- return nil
59
- }
60
- klog .Infof ("%d external secret found: %s" , index , secret .Name )
61
- klog .Info ("We are going to renew the external certificate for the tenant..." )
62
- // Get the new certificate generated by cert-manager
63
- tenantSecretName := tenant .Spec .ExternalCertSecret [0 ].Name
64
- data , err := c .kubeClientSet .CoreV1 ().Secrets (tenant .Namespace ).Get (context .Background (), tenantSecretName , metav1.GetOptions {})
65
- if err != nil {
66
- klog .Errorf ("Couldn't get the certificate due to error %s" , err )
67
- return err
68
- }
69
- if data == nil || len (data .Data ) <= 0 {
70
- klog .Errorf ("certificate's data can't be empty: %s" , data )
71
- return errors .New ("empty cert data" )
72
- }
73
- CACertificate := data .Data [certs .CAPublicCertFile ]
74
- if CACertificate == nil || len (CACertificate ) <= 0 {
75
- klog .Errorf ("ca.crt certificate data can't be empty: %s" , CACertificate )
76
- return errors .New ("empty cert ca data" )
77
- }
78
- klog .Info ("certificate data is not empty, proceed with renewal" )
79
- // Delete the secret that starts with operator-ca-tls- because it is expired
80
- err = c .kubeClientSet .CoreV1 ().Secrets (miniov2 .GetNSFromFile ()).Delete (context .Background (), secret .Name , metav1.DeleteOptions {})
81
- if err != nil {
82
- klog .Infof ("There was an error when deleting the secret: %s" , err )
83
- return err
84
- }
85
- // Create the new secret that contains the new certificate
86
- newSecret := & corev1.Secret {
87
- Type : "Opaque" ,
88
- ObjectMeta : metav1.ObjectMeta {
89
- Name : secret .Name ,
90
- Namespace : miniov2 .GetNSFromFile (),
91
- },
92
- Data : map [string ][]byte {
93
- certs .CAPublicCertFile : CACertificate ,
94
- },
95
- }
96
- _ , err = c .kubeClientSet .CoreV1 ().Secrets (miniov2 .GetNSFromFile ()).Create (context .Background (), newSecret , metav1.CreateOptions {})
97
- if err != nil {
98
- klog .Errorf ("Secret not created %s" , err )
99
- return err
100
- }
101
- // Reload CA certificates
102
- c .createTransport ()
103
- // Rollout the Operator Deployment to use new certificate and trust the tenant.
104
- operatorDeployment , err := c .kubeClientSet .AppsV1 ().Deployments (miniov2 .GetNSFromFile ()).Get (context .Background (), miniov2 .GetNSFromFile (), metav1.GetOptions {})
105
- if err != nil || operatorDeployment == nil {
106
- klog .Errorf ("Couldn't retrieve the deployment %s" , err )
107
- return err
108
- }
109
- operatorDeployment .Spec .Template .ObjectMeta .Name = miniov2 .GetNSFromFile ()
110
- operatorDeployment , err = c .kubeClientSet .AppsV1 ().Deployments (miniov2 .GetNSFromFile ()).Update (context .Background (), operatorDeployment , metav1.UpdateOptions {})
111
- if err != nil {
112
- klog .Errorf ("There was an error on deployment update %s" , err )
113
- return err
114
- }
115
- klog .Info ("external certificate successfully renewed for the tenant" )
116
- return nil
117
- }
118
-
119
- // reloadTenantExternalCerts reloads Tenant external certificates
120
- func (c * Controller ) reloadTenantExternalCerts (tenant * miniov2.Tenant ) error {
121
- externalCertSecret := tenant .Spec .ExternalCertSecret
122
- if externalCertSecret != nil {
123
- // Check that there is a secret that starts with "operator-ca-tls-" to proceed with the renewal
124
- secretsAvailableAtOperatorNS , err := c .kubeClientSet .CoreV1 ().Secrets (miniov2 .GetNSFromFile ()).List (context .Background (), metav1.ListOptions {})
125
- if err != nil {
126
- klog .Info ("No external certificates are found under the multi-tenancy architecture to handle." )
127
- return nil
128
- }
129
- klog .Info ("there are secret(s) for the operator" )
130
- for index , secret := range secretsAvailableAtOperatorNS .Items {
131
- err = c .renewCert (secret , index , tenant )
132
- if err != nil {
133
- klog .Errorf ("There was an error while renewing the cert: %s" , err )
134
- return err
135
- }
136
- }
137
- }
138
- return nil
139
- }
140
-
141
48
// getTenantCredentials returns a combination of env, credsSecret and Configuration tenant credentials
142
49
func (c * Controller ) getTenantCredentials (ctx context.Context , tenant * miniov2.Tenant ) (map [string ][]byte , error ) {
143
50
// Configuration for tenant can be passed using 2 different sources, tenant.spec.env and config.env secret
0 commit comments