@@ -70,21 +70,14 @@ type DeviceSpec struct {
7070type TLS struct {
7171 // The CA certificate to verify the server's identity.
7272 // +required
73- CA * CertificateAuthority `json:"ca"`
73+ CA * corev1. SecretKeySelector `json:"ca"`
7474
7575 // The client certificate and private key to use for mutual TLS authentication.
7676 // Leave empty if mTLS is not desired.
7777 // +optional
7878 Certificate * CertificateSource `json:"certificate,omitempty"`
7979}
8080
81- // CertificateAuthority represents a source for the value of a certificate authority.
82- type CertificateAuthority struct {
83- // The secret must contain the following key: 'ca.crt'.
84- // +required
85- SecretRef * corev1.SecretReference `json:"secretRef,omitempty"`
86- }
87-
8881// Bootstrap defines the configuration for device bootstrap.
8982type Bootstrap struct {
9083 // Template defines the multiline string template that contains the initial configuration for the device.
@@ -230,7 +223,7 @@ type LogServer struct {
230223
231224 // The destination port number for syslog UDP messages to
232225 // the server. The default is 514.
233- // +kubebuilder:validation:Default =514
226+ // +kubebuilder:default =514
234227 // +optional
235228 Port int64 `json:"port"`
236229}
@@ -436,7 +429,7 @@ type CertificateSource struct {
436429type PasswordSource struct {
437430 // Selects a key of a secret.
438431 // +required
439- SecretKeyRef * corev1.SecretReference `json:"secretKeyRef,omitempty"`
432+ SecretKeyRef * corev1.SecretKeySelector `json:"secretKeyRef,omitempty"`
440433}
441434
442435// DeviceStatus defines the observed state of Device.
@@ -494,6 +487,57 @@ type Device struct {
494487 Status DeviceStatus `json:"status,omitempty"`
495488}
496489
490+ // GetSecretRefs returns the list of secrets referenced in the [Device] resource.
491+ func (d * Device ) GetSecretRefs () []corev1.SecretReference {
492+ refs := []corev1.SecretReference {}
493+ if d .Spec .SecretRef != nil {
494+ refs = append (refs , * d .Spec .SecretRef )
495+ }
496+ if d .Spec .TLS != nil {
497+ refs = append (refs , corev1.SecretReference {Name : d .Spec .TLS .CA .Name })
498+ if d .Spec .TLS .Certificate != nil {
499+ refs = append (refs , * d .Spec .TLS .Certificate .SecretRef )
500+ }
501+ }
502+ if d .Spec .Bootstrap != nil && d .Spec .Bootstrap .Template != nil {
503+ if d .Spec .Bootstrap .Template .SecretRef != nil {
504+ refs = append (refs , corev1.SecretReference {Name : d .Spec .Bootstrap .Template .SecretRef .Name })
505+ }
506+ }
507+ if d .Spec .PKI != nil {
508+ for _ , cert := range d .Spec .PKI .Certificates {
509+ if cert .Source != nil && cert .Source .SecretRef != nil {
510+ refs = append (refs , * cert .Source .SecretRef )
511+ }
512+ }
513+ }
514+ for _ , user := range d .Spec .User {
515+ refs = append (refs , corev1.SecretReference {Name : user .Password .SecretKeyRef .Name })
516+ }
517+ for i := range refs {
518+ if refs [i ].Namespace == "" {
519+ refs [i ].Namespace = d .Namespace
520+ }
521+ }
522+ return refs
523+ }
524+
525+ // GetConfigMapRefs returns the list of configmaps referenced in the [Device] resource.
526+ func (d * Device ) GetConfigMapRefs () []corev1.ObjectReference {
527+ refs := []corev1.ObjectReference {}
528+ if d .Spec .Bootstrap != nil && d .Spec .Bootstrap .Template != nil {
529+ if d .Spec .Bootstrap .Template .ConfigMapRef != nil {
530+ refs = append (refs , corev1.ObjectReference {Name : d .Spec .Bootstrap .Template .ConfigMapRef .Name })
531+ }
532+ }
533+ for i := range refs {
534+ if refs [i ].Namespace == "" {
535+ refs [i ].Namespace = d .Namespace
536+ }
537+ }
538+ return refs
539+ }
540+
497541// +kubebuilder:object:root=true
498542
499543// DeviceList contains a list of Device.
0 commit comments