@@ -23,37 +23,47 @@ const (
2323 KeyRadSecTLS = "radsec-tls.conf"
2424)
2525
26- // WriteRadiusConfig renders clients.conf from the given client list and patches
27- // the clients.conf key in the named Kubernetes Secret.
28- func WriteRadiusConfig (ctx context.Context , k8s kubernetes.Interface , namespace , secretName string , clients []RadiusClient ) error {
29- return patchSecretKey (ctx , k8s , namespace , secretName , KeyClientsConf , []byte (RenderClientsConf (clients )))
26+ // WriteRadiusConfig renders clients.conf from the given client list, patches the
27+ // key in the named Kubernetes Secret, and triggers a FreeRADIUS rollout restart.
28+ func WriteRadiusConfig (ctx context.Context , k8s kubernetes.Interface , namespace , secretName , deployment string , clients []RadiusClient ) error {
29+ if err := patchSecretKey (ctx , k8s , namespace , secretName , KeyClientsConf , []byte (RenderClientsConf (clients ))); err != nil {
30+ return err
31+ }
32+ return Reload (ctx , k8s , namespace , deployment )
3033}
3134
3235// WriteRadSecTLS renders and patches the radsec-tls.conf key in the named K8s Secret.
33- // Returns (didUpdate, err). didUpdate is false when the existing value is identical .
34- func WriteRadSecTLS (ctx context.Context , k8s kubernetes.Interface , namespace , secretName string , checkCRL , proxyProtocol bool ) ( bool , error ) {
36+ // If the content changed, FreeRADIUS is reloaded. No-op (no reload) when unchanged .
37+ func WriteRadSecTLS (ctx context.Context , k8s kubernetes.Interface , namespace , secretName , deployment string , checkCRL , proxyProtocol bool ) error {
3538 rendered := RenderRadSecTLS (checkCRL , proxyProtocol )
3639 existing , err := k8s .CoreV1 ().Secrets (namespace ).Get (ctx , secretName , metav1.GetOptions {})
3740 if err == nil && string (existing .Data [KeyRadSecTLS ]) == rendered {
38- return false , nil
41+ return nil
3942 }
40- return true , patchSecretKey (ctx , k8s , namespace , secretName , KeyRadSecTLS , []byte (rendered ))
43+ if err := patchSecretKey (ctx , k8s , namespace , secretName , KeyRadSecTLS , []byte (rendered )); err != nil {
44+ return err
45+ }
46+ return Reload (ctx , k8s , namespace , deployment )
4147}
4248
43- // WriteRadSecServerCert writes all FreeRADIUS TLS material to the named K8s Secret:
49+ // WriteRadSecServerCert writes all FreeRADIUS TLS material to the named K8s Secret
50+ // and triggers a FreeRADIUS rollout restart:
4451// - tls.crt / tls.key: server cert presented to RadSec clients and EAP supplicants
4552// - ca.pem: RadSec CA chain; verifies connecting router client certificates
46- // - wifi-ca.pem: WiFi CA cert ; verifies EAP-TLS user certificates
47- func WriteRadSecServerCert (ctx context.Context , k8s kubernetes.Interface , namespace , secretName string , certPEM , keyPEM , caPEM , wifiCAPEM []byte ) error {
48- return UpsertSecret (ctx , k8s , & corev1.Secret {
53+ // - wifi-ca.pem: WiFi CA chain ; verifies EAP-TLS user client certificates
54+ func WriteRadSecServerCert (ctx context.Context , k8s kubernetes.Interface , namespace , secretName , deployment string , certPEM , keyPEM , caPEM , wifiCAPEM []byte ) error {
55+ if err := UpsertSecret (ctx , k8s , & corev1.Secret {
4956 ObjectMeta : metav1.ObjectMeta {Name : secretName , Namespace : namespace },
5057 Data : map [string ][]byte {
5158 "tls.crt" : certPEM ,
5259 "tls.key" : keyPEM ,
5360 "ca.pem" : caPEM ,
5461 "wifi-ca.pem" : wifiCAPEM ,
5562 },
56- })
63+ }); err != nil {
64+ return err
65+ }
66+ return Reload (ctx , k8s , namespace , deployment )
5767}
5868
5969// EnsureConfigSecret creates the combined PINT config secret with all keys
@@ -72,13 +82,6 @@ func EnsureConfigSecret(ctx context.Context, k8s kubernetes.Interface, namespace
7282 })
7383}
7484
75- // patchSecretKey updates a single key without touching the rest of the secret,
76- // avoiding races with other components that may patch different keys concurrently.
77- // PatchSecretKey updates a single key in an existing K8s Secret via a merge patch.
78- func PatchSecretKey (ctx context.Context , k8s kubernetes.Interface , namespace , secretName , key string , value []byte ) error {
79- return patchSecretKey (ctx , k8s , namespace , secretName , key , value )
80- }
81-
8285func patchSecretKey (ctx context.Context , k8s kubernetes.Interface , namespace , secretName , key string , value []byte ) error {
8386 p , err := json .Marshal (map [string ]interface {}{
8487 "data" : map [string ][]byte {key : value },
@@ -110,7 +113,11 @@ func createIfAbsent(ctx context.Context, k8s kubernetes.Interface, secret *corev
110113
111114// Reload triggers a rollout restart of the FreeRADIUS deployment by patching
112115// the pod template annotation, equivalent to kubectl rollout restart.
116+ // A no-op when deployment is empty (e.g. FreeRADIUS is disabled).
113117func Reload (ctx context.Context , k8s kubernetes.Interface , namespace , deployment string ) error {
118+ if deployment == "" {
119+ return nil
120+ }
114121 patch := fmt .Sprintf (
115122 `{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":%q}}}}}` ,
116123 time .Now ().Format (time .RFC3339 ),
0 commit comments