Skip to content

Commit de6bfed

Browse files
moweonleedeveloper-account
andauthored
added feature to provide imagePullSecrets and imagePullPolicy to runner images when pulling. (#791)
Co-authored-by: developer-account <[email protected]>
1 parent f8172da commit de6bfed

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

charts/function-mesh-operator/templates/controller-manager-configmap.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ data:
1414
{{- if .Values.controllerManager.runnerImages }}
1515
runnerImages:
1616
{{ toYaml .Values.controllerManager.runnerImages | indent 6 }}
17+
{{- end }}
18+
{{- if .Values.controllerManager.runnerImagePullSecrets }}
19+
runnerImagePullSecrets:
20+
{{ toYaml .Values.controllerManager.runnerImagePullSecrets | indent 6 }}
21+
{{- end }}
22+
{{- if .Values.controllerManager.runnerImagePullPolicy }}
23+
runnerImagePullPolicy:
24+
{{ toYaml .Values.controllerManager.runnerImagePullPolicy | indent 6 }}
1725
{{- end }}
1826
{{- if .Values.controllerManager.resourceLabels }}
1927
resourceLabels:

controllers/spec/common.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,14 @@ func generateAnnotations(customAnnotations ...map[string]string) map[string]stri
19231923
return annotations
19241924
}
19251925

1926+
func getFunctionRunnerImagePullSecret() []map[string]string {
1927+
return Configs.RunnerImagePullSecrets
1928+
}
1929+
1930+
func getFunctionRunnerImagePullPolicy() corev1.PullPolicy {
1931+
return Configs.RunnerImagePullPolicy
1932+
}
1933+
19261934
func getFunctionRunnerImage(spec *v1alpha1.FunctionSpec) string {
19271935
runtime := &spec.Runtime
19281936
img := spec.Image
@@ -1940,6 +1948,14 @@ func getFunctionRunnerImage(spec *v1alpha1.FunctionSpec) string {
19401948
return DefaultRunnerImage
19411949
}
19421950

1951+
func getSinkRunnerImagePullSecret() []map[string]string {
1952+
return Configs.RunnerImagePullSecrets
1953+
}
1954+
1955+
func getSinkRunnerImagePullPolicy() corev1.PullPolicy {
1956+
return Configs.RunnerImagePullPolicy
1957+
}
1958+
19431959
func getSinkRunnerImage(spec *v1alpha1.SinkSpec) string {
19441960
img := spec.Image
19451961
if img != "" {
@@ -1952,6 +1968,14 @@ func getSinkRunnerImage(spec *v1alpha1.SinkSpec) string {
19521968
return DefaultRunnerImage
19531969
}
19541970

1971+
func getSourceRunnerImagePullSecret() []map[string]string {
1972+
return Configs.RunnerImagePullSecrets
1973+
}
1974+
1975+
func getSourceRunnerImagePullPolicy() corev1.PullPolicy {
1976+
return Configs.RunnerImagePullPolicy
1977+
}
1978+
19551979
func getSourceRunnerImage(spec *v1alpha1.SourceSpec) string {
19561980
img := spec.Image
19571981
if img != "" {

controllers/spec/controller_configs.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package spec
2020
import (
2121
"os"
2222

23+
corev1 "k8s.io/api/core/v1"
2324
"sigs.k8s.io/yaml"
2425
)
2526

@@ -31,9 +32,11 @@ type RunnerImages struct {
3132
}
3233

3334
type ControllerConfigs struct {
34-
RunnerImages RunnerImages `yaml:"runnerImages,omitempty"`
35-
ResourceLabels map[string]string `yaml:"resourceLabels,omitempty"`
36-
ResourceAnnotations map[string]string `yaml:"resourceAnnotations,omitempty"`
35+
RunnerImages RunnerImages `yaml:"runnerImages,omitempty"`
36+
RunnerImagePullSecrets []map[string]string `yaml:"runnerImagePullSecrets,omitempty"`
37+
RunnerImagePullPolicy corev1.PullPolicy `yaml:"imagePullPolicy,omitempty"`
38+
ResourceLabels map[string]string `yaml:"resourceLabels,omitempty"`
39+
ResourceAnnotations map[string]string `yaml:"resourceAnnotations,omitempty"`
3740
}
3841

3942
var Configs = DefaultConfigs()

controllers/spec/function.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ func MakeFunctionService(function *v1alpha1.Function) *corev1.Service {
5454

5555
func MakeFunctionStatefulSet(ctx context.Context, cli client.Client, function *v1alpha1.Function) (*appsv1.StatefulSet, error) {
5656
objectMeta := MakeFunctionObjectMeta(function)
57+
58+
runnerImagePullSecrets := getFunctionRunnerImagePullSecret()
59+
for _, mapSecret := range runnerImagePullSecrets {
60+
if value, ok := mapSecret["name"]; ok {
61+
function.Spec.Pod.ImagePullSecrets = append(function.Spec.Pod.ImagePullSecrets, corev1.LocalObjectReference{Name: value})
62+
}
63+
}
64+
runnerImagePullPolicy := getFunctionRunnerImagePullPolicy()
65+
function.Spec.ImagePullPolicy = runnerImagePullPolicy
66+
5767
labels := makeFunctionLabels(function)
5868
statefulSet := MakeStatefulSet(objectMeta, function.Spec.Replicas, function.Spec.DownloaderImage,
5969
makeFunctionContainer(function), makeFunctionVolumes(function, function.Spec.Pulsar.AuthConfig), labels, function.Spec.Pod,

controllers/spec/sink.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ func MakeSinkService(sink *v1alpha1.Sink) *corev1.Service {
5151

5252
func MakeSinkStatefulSet(ctx context.Context, cli client.Client, sink *v1alpha1.Sink) (*appsv1.StatefulSet, error) {
5353
objectMeta := MakeSinkObjectMeta(sink)
54+
55+
runnerImagePullSecrets := getSinkRunnerImagePullSecret()
56+
for _, mapSecret := range runnerImagePullSecrets {
57+
if value, ok := mapSecret["name"]; ok {
58+
sink.Spec.Pod.ImagePullSecrets = append(sink.Spec.Pod.ImagePullSecrets, corev1.LocalObjectReference{Name: value})
59+
}
60+
}
61+
runnerImagePullPolicy := getSinkRunnerImagePullPolicy()
62+
sink.Spec.ImagePullPolicy = runnerImagePullPolicy
63+
5464
statefulSet := MakeStatefulSet(objectMeta, sink.Spec.Replicas, sink.Spec.DownloaderImage, makeSinkContainer(sink),
5565
makeSinkVolumes(sink, sink.Spec.Pulsar.AuthConfig), makeSinkLabels(sink), sink.Spec.Pod, sink.Spec.Pulsar.AuthConfig,
5666
sink.Spec.Pulsar.TLSConfig, sink.Spec.Pulsar.PulsarConfig, sink.Spec.Pulsar.AuthSecret, sink.Spec.Pulsar.TLSSecret,

controllers/spec/source.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ func MakeSourceService(source *v1alpha1.Source) *corev1.Service {
5252

5353
func MakeSourceStatefulSet(ctx context.Context, cli client.Client, source *v1alpha1.Source) (*appsv1.StatefulSet, error) {
5454
objectMeta := MakeSourceObjectMeta(source)
55+
56+
runnerImagePullSecrets := getSourceRunnerImagePullSecret()
57+
for _, mapSecret := range runnerImagePullSecrets {
58+
if value, ok := mapSecret["name"]; ok {
59+
source.Spec.Pod.ImagePullSecrets = append(source.Spec.Pod.ImagePullSecrets, corev1.LocalObjectReference{Name: value})
60+
}
61+
}
62+
runnerImagePullPolicy := getSourceRunnerImagePullPolicy()
63+
source.Spec.ImagePullPolicy = runnerImagePullPolicy
64+
5565
statefulSet := MakeStatefulSet(objectMeta, source.Spec.Replicas, source.Spec.DownloaderImage, makeSourceContainer(source),
5666
makeSourceVolumes(source, source.Spec.Pulsar.AuthConfig), makeSourceLabels(source), source.Spec.Pod, source.Spec.Pulsar.AuthConfig,
5767
source.Spec.Pulsar.TLSConfig, source.Spec.Pulsar.PulsarConfig, source.Spec.Pulsar.AuthSecret, source.Spec.Pulsar.TLSSecret,

0 commit comments

Comments
 (0)