Skip to content

Allow up local detection by operator #2063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Allow up local detection by operator #2063

wants to merge 1 commit into from

Conversation

dofinn
Copy link

@dofinn dofinn commented Oct 15, 2019

Description of the change:
When operator-sdk up local is called. Set OPERATOR_UP_LOCAL=true

Motivation for the change:
When developing locally, it would be convenient to detect this in
the actual operator code so things like metrics can be bypassed.

With the OPERATOR_UP_LOCAL=true, operators can skip certain
bootstrapping tasks like attempting to register with a metrics service
while still maintaining logic for registering failures in production.

An example can be seen below:

	// detect if operator-sdk up local is run
	detectLocal := os.Getenv("OPERATOR_UP_LOCAL")

	// Configure metrics. If it errors, log the error and exit
	if detectLocal != "true" {
		if err := metrics.ConfigureMetrics(context.TODO(), *metricsServer); err != nil {
			log.Error(err, "Failed to configure Metrics")
			os.Exit(1)
		}
	}

When developing locally, it would be convient to detect this in
the actual operator code so things like metrics can be bypassed.

With the OPERATOR_UP_LOCAL=true, operators can skip certain
bootstrapping tasks like attempting to register with a metrics service
while still maintaining logic for registering failures in production.
@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Oct 15, 2019
@dofinn
Copy link
Author

dofinn commented Oct 15, 2019

/retest

@openshift-ci-robot
Copy link

@dofinn: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws-ansible 9f1f5d4 link /test e2e-aws-ansible

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@AlexNPavel
Copy link
Contributor

This is actually already implemented. It's used to disable metrics and leader election on local mode runs, but I suppose it could be used by the user as well, we just don't have it documented. When using up local, we set OSDK_FORCE_RUN_MODE=local: https://github.com/operator-framework/operator-sdk/blob/master/cmd/operator-sdk/up/local.go#L142

@joelanford
Copy link
Member

Since this is already implemented, I'm going to close this PR.

IMO, we should not document this and should instead advocate that users that need more advanced control of various go commands that are wrapped by operator-sdk should instead use a Makefile and implement their own logic in custom targets. See #1600 (comment) for more background.

@joelanford joelanford closed this Oct 15, 2019
@dofinn
Copy link
Author

dofinn commented Oct 16, 2019

@joelanford @AlexNPavel Thank you for taking the time to enlighten me on this.

Seems like this is a suitable thing to document, why hide it? If you are going to advocate users to edit their own Makefile, I would recommend at least adding that to the FAQ: https://github.com/operator-framework/operator-sdk/blob/master/doc/faq.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants