Skip to content

Commit faba093

Browse files
committed
refnie
Signed-off-by: kangclzjc <[email protected]>
1 parent fde47c4 commit faba093

File tree

5 files changed

+9
-134
lines changed

5 files changed

+9
-134
lines changed

docs/api-reference/operator-api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ _Appears in:_
815815
| Field | Description | Default | Validation |
816816
| --- | --- | --- | --- |
817817
| `secretName` _string_ | SecretName is the name of the secret containing the webhook server certificate.<br />Default: grove-webhook-server-cert | | |
818-
| `certManagerEnabled` _boolean_ | CertManagerEnabled indicates whether to use cert-manager for certificate management.<br />When true, the operator waits for cert-manager to provide certificates.<br />When false, the operator checks if certificates exist and auto-generates them if not.<br />This requires cert-manager to be installed in the cluster when set to true.<br />Default: false | | |
818+
| `certManagerEnabled` _boolean_ | CertManagerEnabled indicates whether to use cert-manager for certificate management.<br />When true, the operator waits for cert-manager to provide certificates.<br />When false, behavior depends on AutoProvision.<br />This requires cert-manager to be installed in the cluster when set to true.<br />Default: false | | |
819+
| `autoProvision` _boolean_ | AutoProvision indicates whether to use cert-controller for automatic certificate generation.<br />When true, cert-controller generates and manages certificates automatically.<br />When false, certificates are expected to be provided externally (e.g., via Helm chart or manual Secret creation).<br />This field is ignored when CertManagerEnabled is true.<br />Default: true | | |
819820

820821

821822
#### WebhookServer

operator/api/config/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/charts/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ config:
4646
server:
4747
webhooks:
4848
port: 9443
49-
# certDir is the directory path where certificate files are located.
49+
# serverCertDir is the directory path where certificate files are located.
5050
# The operator will look for tls.crt and tls.key in this directory.
5151
# Default: /etc/grove-operator/webhook-certs
5252
serverCertDir: /etc/grove-operator/webhook-certs

operator/hack/prepare-charts.sh

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,13 @@
1818
set -o errexit
1919
set -o nounset
2020
set -o pipefail
21-
source $(dirname $0)/openssl-utils.sh
2221

2322
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
2423
OPERATOR_GO_MODULE_ROOT="$(dirname "$SCRIPT_DIR")"
2524
PROJECT_ROOT="$(dirname "$OPERATOR_GO_MODULE_ROOT")"
2625
SCHEDULER_GO_MODULE_ROOT="${PROJECT_ROOT}/scheduler"
2726
CHARTS_DIR="${OPERATOR_GO_MODULE_ROOT}/charts"
2827

29-
function initialize_pki_resources() {
30-
if [[ $# -ne 2 ]]; then
31-
echo -e "${FUNCNAME[0]} requires 2 arguments: namespace and cert-expiry"
32-
exit 1
33-
fi
34-
35-
local namespace="$1"
36-
local cert_expiry="$2"
37-
local generation_required=false
38-
39-
target_path="${OPERATOR_GO_MODULE_ROOT}/charts/pki-resources"
40-
if [ ! -d ${target_path} ]; then
41-
mkdir -p ${target_path}
42-
generation_required=true
43-
fi
44-
45-
if ${generation_required} || ! all_pki_resources_exist; then
46-
echo "Generating PKI resources..."
47-
rm -rf ${target_path}/*
48-
pki::generate_resources "${target_path}" "${namespace}"
49-
fi
50-
}
51-
52-
function all_pki_resources_exist() {
53-
sourceDir="${OPERATOR_GO_MODULE_ROOT}/charts/pki-resources/"
54-
PKI_RESOURCES=(
55-
"ca.crt"
56-
"ca.key"
57-
"server.crt"
58-
"server.key"
59-
)
60-
for resource in "${PKI_RESOURCES[@]}"; do
61-
local resourcePath="${sourceDir}/${resource}"
62-
if [ ! -f ${resourcePath} ]; then
63-
return 1
64-
fi
65-
done
66-
return 0
67-
}
68-
6928
function copy_crds() {
7029
target_path="${OPERATOR_GO_MODULE_ROOT}/charts/crds"
7130
echo "Creating ${target_path} to copy the CRDs if not present..."
@@ -97,8 +56,4 @@ function copy_crds() {
9756
}
9857

9958
echo "Copying CRDs to helm charts..."
100-
copy_crds
101-
102-
# Allow namespace override via environment variable, default to grove-system
103-
GROVE_NAMESPACE="${GROVE_NAMESPACE:-grove-system}"
104-
initialize_pki_resources "${GROVE_NAMESPACE}" 365
59+
copy_crds

operator/internal/controller/cert/cert.go

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
package cert
1818

1919
import (
20-
"crypto/x509"
21-
"encoding/pem"
2220
"fmt"
2321
"os"
2422
"strings"
25-
"time"
2623

2724
"github.com/ai-dynamo/grove/operator/internal/constants"
2825
authorizationwebhook "github.com/ai-dynamo/grove/operator/internal/webhook/admission/pcs/authorization"
@@ -54,19 +51,15 @@ func ManageWebhookCerts(mgr ctrl.Manager, certDir string, secretName string, aut
5451

5552
logger := ctrl.Log.WithName("cert-management")
5653

57-
// If cert-manager is enabled, wait for it to provide certificates
5854
if certManagerEnabled {
5955
logger.Info("Using cert-manager for certificate management",
6056
"secretName", secretName, "certDir", certDir)
61-
go waitForExternalCerts(logger, certDir, certsReadyCh)
6257
return nil
6358
}
6459

65-
// If auto-provision is disabled, wait for externally provided certificates
6660
if !autoProvision {
6761
logger.Info("Using externally provided certificates",
6862
"certDir", certDir, "secretName", secretName)
69-
go waitForExternalCerts(logger, certDir, certsReadyCh)
7063
return nil
7164
}
7265

@@ -142,82 +135,3 @@ func getOperatorNamespace() (string, error) {
142135
}
143136
return namespace, nil
144137
}
145-
146-
// certsExist checks if both certificate and key files exist and have content in the specified directory
147-
func certsExist(certDir string) bool {
148-
certPath := fmt.Sprintf("%s/tls.crt", certDir)
149-
keyPath := fmt.Sprintf("%s/tls.key", certDir)
150-
return fileExistsWithContent(certPath) && fileExistsWithContent(keyPath)
151-
}
152-
153-
// waitForExternalCerts waits for externally managed certificates to be available
154-
// in the specified directory. This is used when cert-manager is enabled.
155-
func waitForExternalCerts(logger logr.Logger, certDir string, certsReadyCh chan struct{}) {
156-
const (
157-
maxRetries = 30
158-
retryInterval = 2 * time.Second
159-
certFileName = "tls.crt"
160-
keyFileName = "tls.key"
161-
)
162-
163-
certPath := fmt.Sprintf("%s/%s", certDir, certFileName)
164-
keyPath := fmt.Sprintf("%s/%s", certDir, keyFileName)
165-
166-
for i := 0; i < maxRetries; i++ {
167-
// Check if both certificate and key files exist
168-
certExists := fileExists(certPath)
169-
keyExists := fileExists(keyPath)
170-
171-
if certExists && keyExists {
172-
logger.Info("External certificates found and ready",
173-
"certPath", certPath, "keyPath", keyPath)
174-
close(certsReadyCh)
175-
return
176-
}
177-
178-
if i < maxRetries-1 {
179-
logger.Info("Waiting for external certificates to be mounted",
180-
"attempt", i+1, "maxRetries", maxRetries,
181-
"certExists", certExists, "keyExists", keyExists)
182-
time.Sleep(retryInterval)
183-
}
184-
}
185-
186-
logger.Error(fmt.Errorf("timeout waiting for external certificates"),
187-
"Failed to find certificates after maximum retries",
188-
"certPath", certPath, "keyPath", keyPath)
189-
// Don't close the channel - this will cause the readiness check to fail
190-
}
191-
192-
// fileExists checks if a file exists and is not a directory
193-
func fileExists(path string) bool {
194-
info, err := os.Stat(path)
195-
if err != nil {
196-
return false
197-
}
198-
return !info.IsDir()
199-
}
200-
201-
// fileExistsWithContent checks if a file exists and contains valid PEM data
202-
func fileExistsWithContent(path string) bool {
203-
data, err := os.ReadFile(path)
204-
if err != nil || len(data) == 0 {
205-
return false
206-
}
207-
208-
// Try to decode PEM block to verify it's valid
209-
block, _ := pem.Decode(data)
210-
if block == nil || len(block.Bytes) == 0 {
211-
return false
212-
}
213-
214-
// For certificate files, try to parse as X.509
215-
// For key files, just having valid PEM is enough
216-
if strings.Contains(path, "tls.crt") || strings.Contains(path, "ca.crt") {
217-
_, err := x509.ParseCertificate(block.Bytes)
218-
return err == nil
219-
}
220-
221-
// For key files (tls.key), valid PEM block is sufficient
222-
return true
223-
}

0 commit comments

Comments
 (0)