-
Notifications
You must be signed in to change notification settings - Fork 52
WIP: [not merge] - just todo's and questions #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
# todo: we need to add the following for we ensure that all exported methods from the lib will be doc | ||
# E.g exported method `PostHookFunc.Exec` should have comment or be unexported (golint) | ||
issues: | ||
# don't skip warning about doc comments | ||
exclude-use-default: false | ||
|
||
# restore some of the defaults | ||
# (fill in the rest as needed) | ||
exclude-rules: | ||
- linters: [errcheck] | ||
text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked" | ||
# todo(camilamacedo86): missing checks - IMO we need to apply here the same ones which are enable for kb | ||
linters: | ||
disable-all: true | ||
enable: | ||
- govet | ||
- deadcode | ||
- dupl # need to fix issues found with this check | ||
- errcheck | ||
- staticcheck | ||
- unused | ||
- goconst # need to fix issues found with this check | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- golint | ||
- gosec | ||
- gosimple | ||
- structcheck | ||
- varcheck | ||
- govet | ||
- ineffassign | ||
- deadcode | ||
- interfacer # need to fix issues found with this check | ||
- lll # need to fix issues found with this check | ||
- maligned # need to fix issues found with this check | ||
- misspell | ||
- nakedret | ||
- prealloc | ||
- scopelint # need to fix issues found with this check | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- varcheck | ||
|
||
run: | ||
deadline: 5m | ||
deadline: 5m |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,49 @@ | ||
# It will be == kb / new layout less the targets to work with GO | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# see that we cannot add the generate (ansible/helm) will not gen code | ||
# go test, vet fmt ^ | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= quay.io/joelanford/nginx-operator | ||
IMG ?= controller:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
all: docker-build | ||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
all: manager | ||
|
||
# Build manager binary | ||
manager: manifests docker-build | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: | ||
run: manifests | ||
go run ../main.go | ||
|
||
# Install CRDs into a cluster | ||
install: | ||
kustomize build config/crd | kubectl apply -f - | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: | ||
kustomize build config/crd | kubectl delete -f - | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: | ||
cd config/manager && kustomize edit set image controller=${IMG} | ||
kustomize build config/default | kubectl apply -f - | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# It is something that we should push to upstream since is valid for all scenarios | ||
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
undeploy: | ||
cd config/manager && kustomize edit set image controller=${IMG} | ||
kustomize build config/default | kubectl delete -f - | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl delete -f - | ||
|
||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
manifests: | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Build the docker image | ||
docker-build: | ||
|
@@ -33,3 +52,35 @@ docker-build: | |
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
ifeq (, $(shell which controller-gen)) | ||
@{ \ | ||
set -e ;\ | ||
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$CONTROLLER_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
Comment on lines
+56
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think we need controller-gen related things since it deals with Go code generation and CRD generation from Go code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. You are right. It will generated RBCA and CRDS based on go code changes. 👍 |
||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
Comment on lines
+73
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this added recently? I think this file started out as the KB Makefile and I did all of this same stripping at one point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the kustomize works as controller-gen to avoid issues in the case of not be installed. More info: kubernetes-sigs/kubebuilder#1430 not too much recently. I think that it is because the first version in SDK of the plugins came from a branch which was outdated and not rebased with the master. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import ( | |
"time" | ||
|
||
"github.com/spf13/pflag" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap" // todo(camilamacedo86): why we are adding this lib? Shuld we not keep it == kube? | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"k8s.io/klog" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
@@ -45,9 +45,11 @@ func printVersion() { | |
"go", runtime.Version(), | ||
"GOOS", runtime.GOOS, | ||
"GOARCH", runtime.GOARCH, | ||
"helm-operator", version.Version) | ||
"helm-operator", version.Version) // Should not we inform the helm plugin version here? So, should it not be part of SDK impl and no lib? | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// The implementation here is equivalent what we have in the | ||
// /operator-sdk/pkg/helm/run.go internal/scaffold/helm/main.go and helm flags | ||
func main() { | ||
var ( | ||
metricsAddr string | ||
|
@@ -62,10 +64,12 @@ func main() { | |
// Deprecated: use defaultMaxConcurrentReconciles | ||
defaultMaxWorkers int | ||
) | ||
|
||
//todo(camilamacedo86): why the port is not 8080? | ||
pflag.StringVar(&metricsAddr, "metrics-addr", "0.0.0.0:8383", "The address the metric endpoint binds to.") | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pflag.BoolVar(&enableLeaderElection, "enable-leader-election", false, | ||
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") | ||
|
||
//todo(camilamacedo86): the following ones has not in the kube. Wy we need the leaderElectionID and leaderElectionNamespace? | ||
pflag.StringVar(&leaderElectionID, "leader-election-id", "", | ||
"Name of the configmap that is used for holding the leader lock.") | ||
pflag.StringVar(&leaderElectionNamespace, "leader-election-namespace", "", | ||
|
@@ -95,7 +99,7 @@ func main() { | |
)) | ||
|
||
printVersion() | ||
|
||
// todo: Should we not to do this deprecations now in SDK (ASAP) and then may we can just remove from here? | ||
// Deprecated: --max-workers flag does not align well with the name of the option it configures on the controller | ||
// (MaxConcurrentReconciles). Flag `--max-concurrent-reconciles` should be used instead. | ||
if pflag.Lookup("max-workers").Changed { | ||
Comment on lines
103
to
105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not to do this deprecations now in SDK (ASAP)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to think about this one more. I definitely see what you're getting at (i.e. let's get |
||
|
@@ -106,7 +110,7 @@ func main() { | |
defaultMaxConcurrentReconciles = defaultMaxWorkers | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// Why we need a flag for `--leader-election-id`? What is the user case that would be required pass this value? | ||
// Deprecated: OPERATOR_NAME environment variable is an artifact of the legacy operator-sdk project scaffolding. | ||
// Flag `--leader-election-id` should be used instead. | ||
if operatorName, found := os.LookupEnv("OPERATOR_NAME"); found { | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -117,12 +121,13 @@ func main() { | |
leaderElectionID = operatorName | ||
} | ||
} | ||
|
||
options := ctrl.Options{ | ||
MetricsBindAddress: "0.0.0.0:8383", | ||
LeaderElection: enableLeaderElection, | ||
MetricsBindAddress: metricsAddr, | ||
LeaderElection: enableLeaderElection, | ||
// todo: add: | ||
Port: 9443, // should not it be == kubebuilder? | ||
LeaderElectionID: leaderElectionID, | ||
LeaderElectionNamespace: leaderElectionNamespace, | ||
LeaderElectionNamespace: leaderElectionNamespace, // todo: why we need the ns? | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NewClient: manager.NewDelegatingClientFunc(), | ||
} | ||
manager.ConfigureWatchNamespaces(&options, setupLog) | ||
|
@@ -137,7 +142,9 @@ func main() { | |
setupLog.Error(err, "unable to load watches.yaml", "path", watchesFile) | ||
os.Exit(1) | ||
} | ||
|
||
// Not for now. Just a thought for the future: Could we not work with markers to inject | ||
// the code based on the helm/ansible charts instead which would allow users | ||
// also add Go code. Could not it be a solution for the hibrid ones? | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, w := range ws { | ||
reconcilePeriod := defaultReconcilePeriod | ||
if w.ReconcilePeriod != nil { | ||
|
@@ -174,6 +181,17 @@ func main() { | |
|
||
// TODO(joelanford): kube-state-metrics? | ||
|
||
// Are we sure that the "https://godoc.org/sigs.k8s.io/controller-runtime/pkg/manager#LeaderElectionRunnable" | ||
// is able to do all that is done with: | ||
// Become the leader before proceeding | ||
// err = leader.Become(ctx, operatorName+"-lock") | ||
// if err != nil { | ||
// log.Error(err, "Failed to become leader.") | ||
// return err | ||
// } | ||
// Should we check with we would need to keep the leader.Become or try to push something to upstream? | ||
// Why we still using it in the legacy projects? | ||
|
||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setupLog.Info("starting manager") | ||
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
setupLog.Error(err, "problem running manager") | ||
|
Uh oh!
There was an error while loading. Please reload this page.