Skip to content

Commit da7475f

Browse files
committed
pass config to mcp platform service
1 parent 4e9e7c4 commit da7475f

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

cmd/openmcp-operator/app/init.go

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,60 @@ func (o *InitOptions) Run(ctx context.Context) error {
114114
if err := o.PlatformCluster.Client().Get(ctx, client.ObjectKeyFromObject(pod), pod); err != nil {
115115
return fmt.Errorf("error fetching own pod %s/%s: %w", podNamespace, podName, err)
116116
}
117-
image := ""
117+
var container *corev1.Container
118118
if len(pod.Spec.Containers) == 1 {
119-
image = pod.Spec.Containers[0].Image
119+
container = &pod.Spec.Containers[0]
120120
} else {
121121
for _, c := range pod.Spec.Containers {
122122
if c.Name == OpenMCPOperatorName {
123-
image = c.Image
123+
container = &c
124124
break
125125
}
126126
}
127127
}
128-
if image == "" {
129-
return fmt.Errorf("unable to determine own image from pod %s/%s", podNamespace, podName)
128+
if container == nil {
129+
return fmt.Errorf("unable to determine main container from pod %s/%s", podNamespace, podName)
130130
}
131131
verbosity := "INFO"
132132
if log.Enabled(logging.DEBUG) {
133133
verbosity = "DEBUG"
134134
}
135135
pullSecrets := pod.Spec.ImagePullSecrets
136136

137+
// identify volumes that need to be mounted in order to have the config available
138+
configPaths := []string{}
139+
volumeMounts := []corev1.VolumeMount{}
140+
volumes := []corev1.Volume{}
141+
next := false
142+
for _, arg := range container.Args {
143+
if next {
144+
configPaths = append(configPaths, arg)
145+
next = false
146+
} else if arg == "--config" {
147+
next = true
148+
} else if suffix, ok := strings.CutPrefix(arg, "--config="); ok {
149+
configPaths = append(configPaths, suffix)
150+
}
151+
}
152+
if len(configPaths) > 0 {
153+
for _, vm := range container.VolumeMounts {
154+
for _, cp := range configPaths {
155+
if strings.HasPrefix(cp, vm.MountPath) {
156+
volumeMounts = append(volumeMounts, vm)
157+
break
158+
}
159+
}
160+
}
161+
for _, v := range pod.Spec.Volumes {
162+
for _, vm := range volumeMounts {
163+
if v.Name == vm.Name {
164+
volumes = append(volumes, v)
165+
break
166+
}
167+
}
168+
}
169+
}
170+
137171
mcpPSName := o.ProviderName
138172
if mcpPSName == "" {
139173
mcpPSName = strings.ToLower(managedcontrolplane.ControllerName)
@@ -167,14 +201,20 @@ func (o *InitOptions) Run(ctx context.Context) error {
167201
}
168202
if _, err := controllerutil.CreateOrUpdate(ctx, o.PlatformCluster.Client(), ps, func() error {
169203
ps.Labels = expectedLabels
170-
ps.Spec.Image = image
204+
ps.Spec.Image = container.Image
171205
ps.Spec.ImagePullSecrets = collections.ProjectSliceToSlice(pullSecrets, func(ref corev1.LocalObjectReference) commonapi.LocalObjectReference {
172206
return commonapi.LocalObjectReference{
173207
Name: ref.Name,
174208
}
175209
})
210+
ps.Spec.ExtraVolumes = volumes
211+
ps.Spec.ExtraVolumeMounts = volumeMounts
176212
ps.Spec.InitCommand = []string{"mcp", "init"}
177213
ps.Spec.RunCommand = []string{"mcp", "run"}
214+
for _, cp := range configPaths {
215+
ps.Spec.InitCommand = append(ps.Spec.InitCommand, "--config="+cp)
216+
ps.Spec.RunCommand = append(ps.Spec.RunCommand, "--config="+cp)
217+
}
178218
ps.Spec.Verbosity = verbosity
179219
return nil
180220
}); err != nil {

cmd/openmcp-operator/app/mcp/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (o *InitOptions) Run(ctx context.Context) error {
7171

7272
log := o.Log.WithName("main")
7373

74+
log.Info("Getting access to the onboarding cluster")
7475
onboardingScheme := runtime.NewScheme()
7576
install.InstallCRDAPIs(onboardingScheme)
7677

cmd/openmcp-operator/app/mcp/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func (o *RunOptions) Run(ctx context.Context) error {
231231
setupLog.Info("Provider name", "value", o.ProviderName)
232232

233233
// get access to the onboarding cluster
234+
setupLog.Info("Getting access to the onboarding cluster")
234235
onboardingScheme := runtime.NewScheme()
235236
install.InstallOperatorAPIsOnboarding(onboardingScheme)
236237

0 commit comments

Comments
 (0)