11package controllers
22
33import (
4+ "regexp"
5+ "strings"
6+
47 appsv1 "k8s.io/api/apps/v1"
58 corev1 "k8s.io/api/core/v1"
69 "k8s.io/apimachinery/pkg/api/resource"
@@ -12,6 +15,14 @@ import (
1215 clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
1316)
1417
18+ var (
19+ // objects need to be RFC-1123 compliant, and k8s uses this regex to test.
20+ // https://github.com/kubernetes/apimachinery/blob/v0.24.2/pkg/util/validation/validation.go
21+ // dns1123LabelFmt "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
22+ // We want to match the opposite.
23+ notdns * regexp.Regexp = regexp .MustCompile ("[[:^alnum:]]" )
24+ )
25+
1526func (r * IpfsReconciler ) statefulSet (m * clusterv1alpha1.Ipfs ,
1627 sts * appsv1.StatefulSet ,
1728 serviceName string ,
@@ -255,6 +266,30 @@ func (r *IpfsReconciler) statefulSet(m *clusterv1alpha1.Ipfs,
255266 ServiceName : serviceName ,
256267 },
257268 }
269+
270+ // Add a follower container for each follow.
271+ for _ , follow := range m .Spec .Follows {
272+ container := corev1.Container {
273+ Name : "ipfs-cluster-follow-" + notdns .ReplaceAllString (strings .ToLower (follow .Name ), "-" ),
274+ Image : "ipfs/ipfs-cluster:v1.0.1" ,
275+ ImagePullPolicy : corev1 .PullIfNotPresent ,
276+ Command : []string {
277+ "ipfs-cluster-follow" ,
278+ follow .Name ,
279+ "run" ,
280+ "--init" ,
281+ follow .Template ,
282+ },
283+ VolumeMounts : []corev1.VolumeMount {
284+ {
285+ Name : "cluster-storage" ,
286+ MountPath : "/data/ipfs-cluster" ,
287+ },
288+ },
289+ }
290+ expected .Spec .Template .Spec .Containers = append (expected .Spec .Template .Spec .Containers , container )
291+ }
292+
258293 expected .DeepCopyInto (sts )
259294 ctrl .SetControllerReference (m , sts , r .Scheme )
260295 return func () error {
0 commit comments