Skip to content

Commit 4374715

Browse files
Add basic control plane configuration and cisco nxos reconciliation
1 parent bfe3dca commit 4374715

File tree

24 files changed

+1255
-197
lines changed

24 files changed

+1255
-197
lines changed

Tiltfile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@
55
# Don't track us.
66
analytics_settings(False)
77

8+
update_settings(k8s_upsert_timeout_secs=60)
9+
810
allow_k8s_contexts(['minikube', 'kind-network'])
911

12+
load("ext://helm_remote", "helm_remote")
13+
14+
helm_remote(
15+
"cert-manager",
16+
version="v1.17.2",
17+
repo_url="https://charts.jetstack.io",
18+
set=["crds.enabled=true"],
19+
namespace="cert-manager",
20+
create_namespace=True,
21+
install_crds=True,
22+
)
23+
1024
docker_build('controller:latest', '.', ignore=['*/*/zz_generated.deepcopy.go', 'config/crd/bases/*'], only=[
1125
'api/', 'cmd/', 'hack/', 'internal/', 'go.mod', 'go.sum', 'Makefile',
1226
])
@@ -20,7 +34,11 @@ k8s_resource('network-operator-controller-manager', resource_deps=['controller-g
2034

2135
# Sample resources with manual trigger mode
2236
k8s_yaml('./config/samples/v1alpha1_device.yaml')
23-
k8s_resource(new_name='leaf1', objects=['leaf1:device'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
37+
k8s_resource(new_name='secret-basic-auth', objects=['secret-basic-auth:secret'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
38+
k8s_resource(new_name='leaf1', objects=['leaf1:device'], resource_deps=['secret-basic-auth'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
39+
40+
k8s_resource(new_name='network-operator-issuer', objects=['network-operator:issuer'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
41+
k8s_resource(new_name='network-operator-ca', objects=['network-operator-ca:certificate'], resource_deps=['network-operator-issuer'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)
2442

2543
k8s_yaml('./config/samples/v1alpha1_interface.yaml')
2644
k8s_resource(new_name='lo0', objects=['lo0:interface'], trigger_mode=TRIGGER_MODE_MANUAL, auto_init=False)

api/v1alpha1/device_types.go

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,14 @@ type DeviceSpec struct {
7070
type 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.
8982
type 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 {
436429
type 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.

api/v1alpha1/groupversion_info.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,15 @@ const (
6767
// AllResourcesReadyReason indicates that all resources owned by the resource are ready.
6868
AllResourcesReadyReason = "AllResourcesReady"
6969
)
70+
71+
// Device reasons that are used specifically for Device objects.
72+
const (
73+
// UnreachableReason indicates that the device is not reachable over the network.
74+
DeviceUnreachableReason string = "Unreachable"
75+
76+
// UnsupportedReason indicates that the device platform is not supported.
77+
DeviceUnsupportedReason string = "Unsupported"
78+
79+
// UnauthenticatedReason indicates that the provided device credentials are not valid.
80+
DeviceUnauthenticatedReason string = "Unauthenticated"
81+
)

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/webhook"
3636

3737
// Import all supported provider implementations.
38+
_ "github.com/ironcore-dev/network-operator/internal/provider/cisco/nxos"
3839
_ "github.com/ironcore-dev/network-operator/internal/provider/openconfig"
3940

4041
"github.com/ironcore-dev/network-operator/api/v1alpha1"

config/crd/bases/network.ironcore.dev_devices.yaml

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ spec:
356356
server.
357357
type: string
358358
port:
359+
default: 514
359360
description: |-
360361
The destination port number for syslog UDP messages to
361362
the server. The default is 514.
@@ -556,22 +557,27 @@ spec:
556557
ca:
557558
description: The CA certificate to verify the server's identity.
558559
properties:
559-
secretRef:
560-
description: 'The secret must contain the following key: ''ca.crt''.'
561-
properties:
562-
name:
563-
description: name is unique within a namespace to reference
564-
a secret resource.
565-
type: string
566-
namespace:
567-
description: namespace defines the space within which
568-
the secret name must be unique.
569-
type: string
570-
type: object
571-
x-kubernetes-map-type: atomic
560+
key:
561+
description: The key of the secret to select from. Must be
562+
a valid secret key.
563+
type: string
564+
name:
565+
default: ""
566+
description: |-
567+
Name of the referent.
568+
This field is effectively required, but due to backwards compatibility is
569+
allowed to be empty. Instances of this type with an empty value here are
570+
almost certainly wrong.
571+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
572+
type: string
573+
optional:
574+
description: Specify whether the Secret or its key must be
575+
defined
576+
type: boolean
572577
required:
573-
- secretRef
578+
- key
574579
type: object
580+
x-kubernetes-map-type: atomic
575581
certificate:
576582
description: |-
577583
The client certificate and private key to use for mutual TLS authentication.
@@ -611,14 +617,25 @@ spec:
611617
secretKeyRef:
612618
description: Selects a key of a secret.
613619
properties:
614-
name:
615-
description: name is unique within a namespace to reference
616-
a secret resource.
620+
key:
621+
description: The key of the secret to select from. Must
622+
be a valid secret key.
617623
type: string
618-
namespace:
619-
description: namespace defines the space within which
620-
the secret name must be unique.
624+
name:
625+
default: ""
626+
description: |-
627+
Name of the referent.
628+
This field is effectively required, but due to backwards compatibility is
629+
allowed to be empty. Instances of this type with an empty value here are
630+
almost certainly wrong.
631+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
621632
type: string
633+
optional:
634+
description: Specify whether the Secret or its key must
635+
be defined
636+
type: boolean
637+
required:
638+
- key
622639
type: object
623640
x-kubernetes-map-type: atomic
624641
required:

config/manager/manager.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ spec:
8787
# TODO(user): Configure the resources accordingly based on the project requirements.
8888
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
8989
resources:
90-
limits:
91-
cpu: 500m
92-
memory: 128Mi
9390
requests:
94-
cpu: 10m
95-
memory: 64Mi
91+
cpu: 50m
92+
memory: 256Mi
93+
limits:
94+
memory: 512Mi
9695
volumeMounts: []
9796
volumes: []
9897
serviceAccountName: controller-manager

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- configmaps
11+
- secrets
12+
verbs:
13+
- get
14+
- list
15+
- watch
716
- apiGroups:
817
- ""
918
resources:

0 commit comments

Comments
 (0)