MCPcopy
hub / github.com/operator-framework/operator-sdk / run

Function run

internal/cmd/helm-operator/run/cmd.go:95–212  ·  view source on GitHub ↗
(cmd *cobra.Command, f *flags.Flags)

Source from the content-addressed store, hash-verified

93}
94
95func run(cmd *cobra.Command, f *flags.Flags) {
96 printVersion()
97 metrics.RegisterBuildInfo(crmetrics.Registry)
98
99 // Load config options from the config at f.ManagerConfigPath.
100 // These options will not override those set by flags.
101 var (
102 options manager.Options
103 err error
104 )
105
106 exitIfUnsupported(options)
107
108 cfg, err := config.GetConfig()
109 if err != nil {
110 log.Error(err, "Failed to get config.")
111 os.Exit(1)
112 }
113
114 // TODO(2.0.0): remove
115 // Deprecated: OPERATOR_NAME environment variable is an artifact of the
116 // legacy operator-sdk project scaffolding. Flag `--leader-election-id`
117 // should be used instead.
118 if operatorName, found := os.LookupEnv("OPERATOR_NAME"); found {
119 log.Info("Environment variable OPERATOR_NAME has been deprecated, use --leader-election-id instead.")
120 if cmd.Flags().Changed("leader-election-id") {
121 log.Info("Ignoring OPERATOR_NAME environment variable since --leader-election-id is set")
122 } else if options.LeaderElectionID == "" {
123 // Only set leader election ID using OPERATOR_NAME if unset everywhere else,
124 // since this env var is deprecated.
125 options.LeaderElectionID = operatorName
126 }
127 }
128
129 //TODO(2.0.0): remove the following checks. they are required just because of the flags deprecation
130 if cmd.Flags().Changed("leader-elect") && cmd.Flags().Changed("enable-leader-election") {
131 log.Error(errors.New("only one of --leader-elect and --enable-leader-election may be set"), "invalid flags usage")
132 os.Exit(1)
133 }
134
135 if cmd.Flags().Changed("metrics-addr") && cmd.Flags().Changed("metrics-bind-address") {
136 log.Error(errors.New("only one of --metrics-addr and --metrics-bind-address may be set"), "invalid flags usage")
137 os.Exit(1)
138 }
139
140 // Set default manager options
141 options = f.ToManagerOptions(options)
142
143 if options.Scheme == nil {
144 options.Scheme = apimachruntime.NewScheme()
145 }
146
147 ws, err := watches.Load(f.WatchesFile)
148 if err != nil {
149 log.Error(err, "Failed to load watches file.")
150 os.Exit(1)
151 }
152

Callers 1

NewCmdFunction · 0.70

Calls 10

RegisterBuildInfoFunction · 0.92
LoadFunction · 0.92
AddFunction · 0.92
NewManagerFactoryFunction · 0.92
printVersionFunction · 0.85
exitIfUnsupportedFunction · 0.85
configureWatchNamespacesFunction · 0.85
configureSelectorsFunction · 0.85
ToManagerOptionsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected