Skip to content

Commit 320e35b

Browse files
committed
Add --namespace command line flag and remove unused flags and fix broken flags
1 parent 8022772 commit 320e35b

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

cmd/mysql-operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func main() {
7777
LeaderElection: true,
7878
LeaderElectionNamespace: opt.LeaderElectionNamespace,
7979
LeaderElectionID: opt.LeaderElectionID,
80+
Namespace: opt.Namespace,
8081
})
8182
if err != nil {
8283
log.Error(err, "unable to create a new manager")

pkg/controller/mysqlbackup/internal/syncer/job.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,13 @@ func (s *jobSyncer) ensurePodSpec(in core.PodSpec) core.PodSpec {
122122
}
123123

124124
in.RestartPolicy = core.RestartPolicyNever
125+
in.ImagePullSecrets = []core.LocalObjectReference{
126+
{Name: s.opt.ImagePullSecretName},
127+
}
125128

126129
in.Containers[0].Name = "backup"
127130
in.Containers[0].Image = s.opt.SidecarImage
128-
in.Containers[0].ImagePullPolicy = core.PullIfNotPresent
131+
in.Containers[0].ImagePullPolicy = s.opt.ImagePullPolicy
129132
in.Containers[0].Args = []string{
130133
"take-backup-to",
131134
s.getBackupCandidate(),

pkg/internal/mysqlcluster/defaults.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package mysqlcluster
1818

1919
import (
2020
"fmt"
21+
2122
core "k8s.io/api/core/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/util/intstr"
@@ -41,6 +42,15 @@ func (cluster *MysqlCluster) SetDefaults(opt *options.Options) {
4142
cluster.Spec.PodSpec.ImagePullPolicy = opt.ImagePullPolicy
4243
}
4344

45+
// set default image pull secrets
46+
if len(cluster.Spec.PodSpec.ImagePullSecrets) == 0 {
47+
if len(opt.ImagePullSecretName) != 0 {
48+
cluster.Spec.PodSpec.ImagePullSecrets = []core.LocalObjectReference{
49+
{Name: opt.ImagePullSecretName},
50+
}
51+
}
52+
}
53+
4454
if len(cluster.Spec.MysqlVersion) == 0 {
4555
cluster.Spec.MysqlVersion = "5.7"
4656
}

pkg/options/options.go

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package options
1919
import (
2020
"os"
2121
"sync"
22-
"time"
2322

2423
"github.com/spf13/pflag"
2524
corev1 "k8s.io/api/core/v1"
@@ -38,23 +37,34 @@ func getFromEnvOrDefault(key, def string) string {
3837

3938
// Options is the data structure that contains information about mysql operator configuration
4039
type Options struct {
40+
// SidecarImage is the image used in sidecar container to serve backups and configure MySQL
4141
SidecarImage string
4242

43+
// MetricsExporterImage is the image for exporter container
4344
MetricsExporterImage string
4445

46+
// ImagePullSecretName is the secret name where are found secrets for pulling images. This is
47+
// the default value and may be overwrite by the cluster .spec.podSpec.imagePullSecrets field.
4548
ImagePullSecretName string
46-
ImagePullPolicy corev1.PullPolicy
49+
// ImagePullPolicy is the default image pull policy
50+
ImagePullPolicy corev1.PullPolicy
4751

48-
OrchestratorURI string
52+
// OrchestratorURI represents the URI where the Orchestrator can be reached.
53+
OrchestratorURI string
54+
// OrchestratorTopologyPassword is the password that is used by Orchestrator to connect to MySQL
55+
// nodes. This field is set in cluster secret as well.
4956
OrchestratorTopologyPassword string
50-
OrchestratorTopologyUser string
51-
52-
JobCompleteSuccessGraceTime time.Duration
53-
54-
HTTPServeAddr string
57+
// OrchestratorTopologyUser is the user that is used by Orchestrator to connect to MySQL
58+
// nodes. This field is set in cluster secret as well.
59+
OrchestratorTopologyUser string
5560

61+
// LeaderElectionNamespace the namespace where the lock resource will be created
5662
LeaderElectionNamespace string
57-
LeaderElectionID string
63+
// LederElectionID the name of the lock resource
64+
LeaderElectionID string
65+
66+
// Namespace where to look after objects. This will limit the operator action range.
67+
Namespace string
5868
}
5969

6070
type pullpolicy corev1.PullPolicy
@@ -81,20 +91,20 @@ func newPullPolicyValue(defaultValue corev1.PullPolicy, v *corev1.PullPolicy) *p
8191
const (
8292
defaultExporterImage = "prom/mysqld-exporter:latest"
8393

84-
defaultImagePullPolicy = corev1.PullIfNotPresent
94+
defaultImagePullPolicy = corev1.PullIfNotPresent
95+
defaultImagePullSecretName = ""
8596

8697
defaultOrchestratorTopologyUser = ""
8798
defaultOrchestratorTopologyPassword = ""
8899

89-
defaultHTTPServerAddr = ":80"
90-
91100
defaultLeaderElectionNamespace = "default"
92101
defaultLeaderElectionID = ""
102+
103+
defaultNamespace = ""
93104
)
94105

95106
var (
96107
defaultSidecarImage = "quay.io/presslabs/mysql-operator-sidecar:" + util.AppVersion
97-
defaultJobGraceTime = 24 * time.Hour
98108
)
99109

100110
// AddFlags registers all mysql-operator needed flags
@@ -104,7 +114,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
104114

105115
fs.StringVar(&o.MetricsExporterImage, "metrics-exporter-image", defaultExporterImage,
106116
"The image for mysql metrics exporter.")
107-
fs.StringVar(&o.ImagePullSecretName, "image-pull-secret", "",
117+
fs.StringVar(&o.ImagePullSecretName, "image-pull-secret", defaultImagePullSecretName,
108118
"The secret name for used as pull secret.")
109119

110120
fs.VarP(newPullPolicyValue(defaultImagePullPolicy, &o.ImagePullPolicy),
@@ -116,16 +126,14 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
116126
"The orchestrator topology password. Can also be set as ORC_TOPOLOGY_PASSWORD environment variable.")
117127
fs.StringVar(&o.OrchestratorTopologyUser, "orchestrator-topology-user", defaultOrchestratorTopologyPassword,
118128
"The orchestrator topology user. Can also be set as ORC_TOPOLOGY_USER environment variable.")
119-
fs.DurationVar(&o.JobCompleteSuccessGraceTime, "job-grace-time", defaultJobGraceTime,
120-
"The time in hours how jobs after completion are keept.")
121-
122-
fs.StringVar(&o.HTTPServeAddr, "http-serve-addr", defaultHTTPServerAddr,
123-
"The address for http server.")
124129

125130
fs.StringVar(&o.LeaderElectionNamespace, "leader-election-namespace", defaultLeaderElectionNamespace,
126131
"The leader election namespace.")
127132
fs.StringVar(&o.LeaderElectionID, "leader-election-id", defaultLeaderElectionID,
128133
"The leader election id.")
134+
135+
fs.StringVar(&o.Namespace, "namespace", defaultNamespace,
136+
"The namespace to restrict the client to watch objects.")
129137
}
130138

131139
var instance *Options
@@ -138,13 +146,13 @@ func GetOptions() *Options {
138146
SidecarImage: defaultSidecarImage,
139147
MetricsExporterImage: defaultExporterImage,
140148

141-
ImagePullPolicy: defaultImagePullPolicy,
142-
JobCompleteSuccessGraceTime: defaultJobGraceTime,
149+
ImagePullPolicy: defaultImagePullPolicy,
150+
ImagePullSecretName: defaultImagePullSecretName,
143151

144-
OrchestratorTopologyUser: "",
145-
OrchestratorTopologyPassword: "",
152+
OrchestratorTopologyUser: defaultOrchestratorTopologyUser,
153+
OrchestratorTopologyPassword: defaultOrchestratorTopologyPassword,
146154

147-
HTTPServeAddr: defaultHTTPServerAddr,
155+
Namespace: defaultNamespace,
148156
}
149157
})
150158

0 commit comments

Comments
 (0)