Skip to content

Commit 3ea6950

Browse files
committed
refactoring configmap to filepath
1 parent a74984e commit 3ea6950

File tree

15 files changed

+292
-467
lines changed

15 files changed

+292
-467
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ FROM gcr.io/distroless/static:nonroot AS manager
3939
LABEL source_repository="https://github.com/ironcore-dev/metal-operator"
4040
WORKDIR /
4141
COPY --from=manager-builder /workspace/manager .
42+
COPY config/manager/ignition-template.yaml /etc/metal-operator/ignition-template.yaml
4243
USER 65532:65532
4344

4445
ENTRYPOINT ["/manager"]

cmd/manager/main.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ import (
1919
// to ensure that exec-entrypoint and run can make use of them.
2020
_ "k8s.io/client-go/plugin/pkg/client/auth"
2121

22-
corev1 "k8s.io/api/core/v1"
2322
"k8s.io/apimachinery/pkg/runtime"
2423
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2524
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
2625
ctrl "sigs.k8s.io/controller-runtime"
27-
"sigs.k8s.io/controller-runtime/pkg/cache"
2826
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
29-
"sigs.k8s.io/controller-runtime/pkg/client"
3027
"sigs.k8s.io/controller-runtime/pkg/healthz"
3128
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3229
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -79,8 +76,7 @@ func main() { // nolint: gocyclo
7976
webhookPort int
8077
enforceFirstBoot bool
8178
enforcePowerOff bool
82-
ignitionConfigMapName string
83-
ignitionConfigMapKey string
79+
ignitionConfigPath string
8480
serverResyncInterval time.Duration
8581
maintenanceResyncInterval time.Duration
8682
powerPollingInterval time.Duration
@@ -119,10 +115,8 @@ func main() { // nolint: gocyclo
119115
"Defines the duration which the bmc waits before reconciling again when bmc has been reset.")
120116
flag.DurationVar(&maintenanceResyncInterval, "maintenance-resync-interval", 2*time.Minute,
121117
"Defines the interval at which the CRD performing maintenance is polled during server maintenance task.")
122-
flag.StringVar(&ignitionConfigMapName, "ignition-configmap-name", "",
123-
"Name of the ConfigMap containing the ignition template. If empty, uses hardcoded template.")
124-
flag.StringVar(&ignitionConfigMapKey, "ignition-configmap-key", "ignition-template.yaml",
125-
"Key in the ConfigMap containing the ignition template.")
118+
flag.StringVar(&ignitionConfigPath, "ignition-config-path", "/etc/metal-operator/ignition-template.yaml",
119+
"Path to the ignition template file.")
126120
flag.StringVar(&registryURL, "registry-url", "", "The URL of the registry.")
127121
flag.StringVar(&registryProtocol, "registry-protocol", "http", "The protocol to use for the registry.")
128122
flag.IntVar(&registryPort, "registry-port", 10000, "The port to use for the registry.")
@@ -289,20 +283,8 @@ func main() { // nolint: gocyclo
289283
})
290284
}
291285

292-
// Configure cache to watch ConfigMaps only in the manager namespace
293-
cacheOptions := cache.Options{
294-
ByObject: map[client.Object]cache.ByObject{
295-
&corev1.ConfigMap{}: {
296-
Namespaces: map[string]cache.Config{
297-
managerNamespace: {},
298-
},
299-
},
300-
},
301-
}
302-
303286
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
304287
Scheme: scheme,
305-
Cache: cacheOptions,
306288
Metrics: metricsServerOptions,
307289
WebhookServer: webhookServer,
308290
HealthProbeBindAddress: probeAddr,
@@ -369,8 +351,7 @@ func main() { // nolint: gocyclo
369351
EnforceFirstBoot: enforceFirstBoot,
370352
EnforcePowerOff: enforcePowerOff,
371353
MaxConcurrentReconciles: serverMaxConcurrentReconciles,
372-
IgnitionConfigMapName: ignitionConfigMapName,
373-
IgnitionConfigMapKey: ignitionConfigMapKey,
354+
IgnitionConfigPath: ignitionConfigPath,
374355
BMCOptions: bmc.Options{
375356
BasicAuth: true,
376357
PowerPollingInterval: powerPollingInterval,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
variant: fcos
2+
version: "1.3.0"
3+
systemd:
4+
units:
5+
- name: docker-install.service
6+
enabled: true
7+
contents: |-
8+
[Unit]
9+
Description=Install Docker
10+
Before=metalprobe.service
11+
[Service]
12+
Restart=on-failure
13+
RestartSec=20
14+
Type=oneshot
15+
RemainAfterExit=yes
16+
ExecStart=/usr/bin/apt-get update
17+
ExecStart=/usr/bin/apt-get install docker.io docker-cli -y
18+
[Install]
19+
WantedBy=multi-user.target
20+
- name: docker.service
21+
enabled: true
22+
- name: metalprobe.service
23+
enabled: true
24+
contents: |-
25+
[Unit]
26+
Description=Run My Docker Container
27+
[Service]
28+
Restart=on-failure
29+
RestartSec=20
30+
ExecStartPre=-/usr/bin/docker stop metalprobe
31+
ExecStartPre=-/usr/bin/docker rm metalprobe
32+
ExecStartPre=/usr/bin/docker pull {{.Image}}
33+
ExecStart=/usr/bin/docker run --network host --privileged --name metalprobe {{.Image}} {{.Flags}}
34+
ExecStop=/usr/bin/docker stop metalprobe
35+
[Install]
36+
WantedBy=multi-user.target
37+
storage:
38+
files: []
39+
passwd:
40+
users:
41+
- name: metal
42+
password_hash: {{.PasswordHash}}
43+
groups: [ "wheel" ]
44+
ssh_authorized_keys: [ {{.SSHPublicKey}} ]

config/rbac/role.yaml

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

dist/chart/IGNITION-CUSTOMIZATION.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Metal Operator Helm Chart - Ignition Template Customization
22

3-
This Helm chart allows you to optionally override the default hardcoded Ignition template used by the metal-operator for bare metal server provisioning.
3+
This Helm chart allows you to optionally override the default Ignition template used by the metal-operator for bare metal server provisioning.
44

55
## Overview
66

7-
The metal-operator uses [Ignition](https://coreos.github.io/ignition/) templates to configure bare metal servers during their first boot. By default, it uses a hardcoded template. You can optionally enable ConfigMap-based template customization to meet your specific requirements.
7+
The metal-operator uses [Ignition](https://coreos.github.io/ignition/) templates to configure bare metal servers during their first boot. The operator includes a default template file baked into the container at `/etc/metal-operator/ignition-template.yaml`. You can optionally override this template by mounting a ConfigMap at the same location.
88

99
## Configuration
1010

@@ -14,15 +14,14 @@ The ignition configuration is controlled by the `ignition` section in `values.ya
1414

1515
```yaml
1616
ignition:
17-
enable: false # Enable/disable ignition ConfigMap override (default: false)
18-
configMapName: "ignition-template" # Name suffix for the ConfigMap
19-
configMapKey: "ignition-template.yaml" # Key in the ConfigMap containing the template
20-
template: | # The actual Ignition template content (only used when enable: true)
17+
override: false # Enable/disable ignition ConfigMap override (default: false)
18+
template: | # The actual Ignition template content (only used when override: true)
2119
# Your custom Ignition template here
2220
```
2321
24-
**Default Behavior**: When `ignition.enable: false` (default), the operator uses its built-in hardcoded template.
25-
**Override Behavior**: When `ignition.enable: true`, the operator uses the ConfigMap template and falls back to hardcoded if ConfigMap is unavailable.
22+
**Default Behavior**: When `ignition.override: false` (default), the operator uses the template file baked into the container image at `/etc/metal-operator/ignition-template.yaml`.
23+
24+
**Override Behavior**: When `ignition.override: true`, a ConfigMap is created and mounted to `/etc/metal-operator/ignition-template.yaml`, replacing the default template file.
2625

2726
### Template Variables
2827

@@ -37,7 +36,7 @@ Your custom template must include these template variables for proper operation:
3736

3837
```yaml
3938
ignition:
40-
enable: true
39+
override: true
4140
template: |
4241
variant: fcos
4342
version: "1.3.0"
@@ -64,19 +63,19 @@ ignition:
6463

6564
## Deployment
6665

67-
### Using Default Hardcoded Template (Recommended)
66+
### Using Default Template (Recommended)
6867

6968
```bash
7069
helm install my-metal-operator ./
7170
```
7271

73-
This uses the built-in hardcoded template. No ConfigMap is created, and the operator works immediately.
72+
This uses the template file baked into the container image. No ConfigMap is created, and the operator works immediately with the default configuration.
7473

7574
### Using Custom Template Override
7675

7776
1. Enable ignition customization:
7877
```bash
79-
helm install my-metal-operator ./ --set ignition.enable=true
78+
helm install my-metal-operator ./ --set ignition.override=true
8079
```
8180

8281
2. Or create a custom values file:
@@ -159,16 +158,22 @@ passwd:
159158

160159
## Troubleshooting
161160

162-
### ConfigMap Not Found
161+
### Template File Not Found
162+
163+
If you see errors about template file not being found:
163164

164-
If you see errors about ConfigMap not being found:
165+
1. Verify the default file exists in the container:
166+
```bash
167+
kubectl exec -n <namespace> deployment/metal-operator-controller-manager -- ls -la /etc/metal-operator/
168+
```
165169

166-
1. Verify the ConfigMap was created:
170+
2. If using ConfigMap override, verify it was created and mounted:
167171
```bash
168172
kubectl get configmap -n <namespace>
173+
kubectl describe deployment -n <namespace> metal-operator-controller-manager
169174
```
170175

171-
2. Check the manager logs:
176+
3. Check the manager logs:
172177
```bash
173178
kubectl logs -n <namespace> deployment/metal-operator-controller-manager
174179
```
@@ -180,12 +185,17 @@ If ignition generation fails due to template syntax:
180185
1. Validate your template syntax offline
181186
2. Check that all required template variables are included
182187
3. Verify the Ignition format is valid
188+
4. If using a custom template, ensure the ConfigMap is properly mounted
183189

184-
### Permission Issues
190+
### Volume Mount Issues
185191

186-
If the controller cannot read the ConfigMap:
187-
1. Verify RBAC permissions include ConfigMap access
188-
2. Check that the ConfigMap is in the correct namespace
192+
If the ConfigMap override is not working:
193+
1. Verify the ConfigMap is mounted correctly:
194+
```bash
195+
kubectl describe pod -n <namespace> -l control-plane=controller-manager
196+
```
197+
2. Check that `ignition.override: true` is set in values
198+
3. Verify RBAC permissions include ConfigMap access
189199

190200
## Examples
191201

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{{- if .Values.ignition.enable }}
1+
{{- if .Values.ignition.override }}
22
apiVersion: v1
33
kind: ConfigMap
44
metadata:
5-
name: {{ include "chart.name" . }}-{{ .Values.ignition.configMapName }}
5+
name: {{ include "chart.name" . }}-ignition-template
66
namespace: {{ .Release.Namespace }}
77
labels:
88
{{- include "chart.labels" . | nindent 4 }}
@@ -12,6 +12,6 @@ data:
1212
# {{.Flags}} - The flags to pass to the metalprobe container, this includes --registry-url and --server-uuid
1313
# {{.SSHPublicKey}} - The SSH public key for the 'metal' user
1414
# {{.PasswordHash}} - The password hash for the 'metal' user
15-
{{ .Values.ignition.configMapKey }}: |
15+
ignition-template.yaml: |
1616
{{ .Values.ignition.template | indent 4 }}
1717
{{- end }}

dist/chart/templates/manager/manager.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ spec:
3434
{{- range .Values.controllerManager.manager.args }}
3535
- {{ . }}
3636
{{- end }}
37-
{{- if .Values.ignition.enable }}
38-
- "--manager-namespace={{ .Release.Namespace }}"
39-
- "--ignition-configmap-name={{ include "chart.name" . }}-{{ .Values.ignition.configMapName }}"
40-
- "--ignition-configmap-key={{ .Values.ignition.configMapKey }}"
41-
{{- end }}
4237
command:
4338
- /manager
4439
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag }}
@@ -66,6 +61,11 @@ spec:
6661
volumeMounts:
6762
- mountPath: /etc/macdb/
6863
name: macdb
64+
{{- if .Values.ignition.override }}
65+
- name: ignition-template
66+
mountPath: /etc/metal-operator
67+
readOnly: true
68+
{{- end }}
6969
{{- if and .Values.webhook.enable .Values.certmanager.enable }}
7070
- name: webhook-cert
7171
mountPath: /tmp/k8s-webhook-server/serving-certs
@@ -92,6 +92,11 @@ spec:
9292
- name: macdb
9393
secret:
9494
secretName: macdb
95+
{{- if .Values.ignition.override }}
96+
- name: ignition-template
97+
configMap:
98+
name: {{ include "chart.name" . }}-ignition-template
99+
{{- end }}
95100
{{- if and .Values.webhook.enable .Values.certmanager.enable }}
96101
- name: webhook-cert
97102
secret:

dist/chart/templates/rbac/configmap_role.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

dist/chart/templates/rbac/configmap_role_binding.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

dist/chart/templates/rbac/role.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ metadata:
77
{{- include "chart.labels" . | nindent 4 }}
88
name: metal-operator-manager-role
99
rules:
10-
- apiGroups:
11-
- ""
12-
resources:
13-
- configmaps
14-
verbs:
15-
- get
16-
- list
17-
- watch
1810
- apiGroups:
1911
- ""
2012
resources:

0 commit comments

Comments
 (0)