This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
/
configmap.go
84 lines (70 loc) · 2.24 KB
/
configmap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package mpi
import (
"fmt"
"strings"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
dcv1alpha1 "github.com/dominodatalab/distributed-compute-operator/api/v1alpha1"
"github.com/dominodatalab/distributed-compute-operator/pkg/controller/actions"
"github.com/dominodatalab/distributed-compute-operator/pkg/controller/core"
)
func ConfigMap() core.OwnedComponent {
return &configMapComponent{}
}
type configMapComponent struct{}
func (c configMapComponent) Reconcile(ctx *core.Context) (ctrl.Result, error) {
cr := objToMPICluster(ctx.Object)
hostFileConfig := createHostFileConfig(cr)
err := actions.CreateOrUpdateOwnedResource(ctx, cr, hostFileConfig)
if err != nil {
return ctrl.Result{}, fmt.Errorf("cannot reconcile hostfile configmap: %w", err)
}
keytabConfig := createKeytabConfig(cr)
if keytabConfig != nil {
err := actions.CreateOrUpdateOwnedResource(ctx, cr, keytabConfig)
if err != nil {
return ctrl.Result{}, fmt.Errorf("cannot reconcile keytab configmap: %w", err)
}
}
return ctrl.Result{}, nil
}
func (c configMapComponent) Kind() client.Object {
return &corev1.ConfigMap{}
}
func createHostFileConfig(cr *dcv1alpha1.MPICluster) *corev1.ConfigMap {
svcName := serviceName(cr, ComponentWorker)
workerName := workerStatefulSetName(cr)
workerReplicas := *cr.Spec.Worker.Replicas
var hostFileBuilder strings.Builder
for idx := 0; idx < int(workerReplicas); idx++ {
entry := fmt.Sprintf("%s-%d.%s\n", workerName, idx, svcName)
hostFileBuilder.WriteString(entry)
}
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configMapName(cr) + "-" + hostFileName,
Namespace: cr.Namespace,
Labels: meta.StandardLabels(cr),
},
Data: map[string]string{
hostFileName: hostFileBuilder.String(),
},
}
}
func createKeytabConfig(cr *dcv1alpha1.MPICluster) *corev1.ConfigMap {
if cr.Spec.KerberosKeytab == nil {
return nil
}
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configMapName(cr) + "-" + keytabName,
Namespace: cr.Namespace,
Labels: meta.StandardLabels(cr),
},
BinaryData: map[string][]byte{
keytabName: cr.Spec.KerberosKeytab.Contents,
},
}
}