Skip to content

Commit

Permalink
(kustomize/v1, go/v3) : Add new LeaderElectionReleaseOnCancel as true…
Browse files Browse the repository at this point in the history
… option commented to let users know when they can use it.
  • Loading branch information
NikhilSharmaWe committed May 5, 2022
1 parent 61b263c commit 97062b2
Show file tree
Hide file tree
Showing 48 changed files with 727 additions and 141 deletions.
2 changes: 1 addition & 1 deletion build/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ steps:
git checkout $${BRANCH_NAME}
git branch --set-upstream-to=origin/$${BRANCH_NAME}
git tag -d ${TAG_NAME}
- name: "goreleaser/goreleaser:v0.147"
- name: "goreleaser/goreleaser:v1.8.3"
entrypoint: "bash"
args: ["build/build_kubebuilder.sh"]
secretEnv: ["GITHUB_TOKEN"]
Expand Down
2 changes: 1 addition & 1 deletion build/cloudbuild_local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Release tar will be in ./cloudbuild

steps:
- name: "goreleaser/goreleaser:v0.147"
- name: "goreleaser/goreleaser:v1.8.3"
entrypoint: "bash"
env: ["SNAPSHOT=1"]
args: ["build/build_kubebuilder.sh"]
2 changes: 1 addition & 1 deletion build/cloudbuild_snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Release tar will be in ./cloudbuild

steps:
- name: "goreleaser/goreleaser:v0.147"
- name: "goreleaser/goreleaser:v1.8.3"
entrypoint: "bash"
env: ["SNAPSHOT=1"]
args: ["build/build_kubebuilder.sh"]
Expand Down
1 change: 1 addition & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
- [go/v3 plugin](./plugins/go-v3-plugin.md)
- [go/v2 plugin](./plugins/go-v2-plugin.md)
- [Declarative V1](./plugins/declarative-v1.md)
- [Kustomize V1](./plugins/kustomize-v1.md)
- [Plugins Versioning](./plugins/plugins-versioning.md)

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ function gen_component_config_tutorial {
header_text "creating tutorial.kubebuilder.io base ..."
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --component-config --license apache2 --owner "The Kubernetes authors"
kubebuilder create api --group config --version v2 --kind ProjectConfig --resource --controller=false --make=false
go mod tidy
make
}

gen_component_config_tutorial
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN): ## Ensure that the directory exists
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
Expand All @@ -119,15 +119,15 @@ CONTROLLER_TOOLS_VERSION ?= v0.8.0
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE):
$(KUSTOMIZE): $(LOCALBIN)
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN):
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST):
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
94 changes: 94 additions & 0 deletions docs/book/src/component-config-tutorial/testdata/project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# project
// TODO(user): Add simple overview of use/purpose

## Description
// TODO(user): An in-depth paragraph about your project and overview of use

## Getting Started
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).

### Running on the cluster
1. Install Instances of Custom Resources:

```sh
kubectl apply -f config/samples/
```

2. Build and push your image to the location specified by `IMG`:

```sh
make docker-build docker-push IMG=<some-registry>/project:tag
```

3. Deploy the controller to the cluster with the image specified by `IMG`:

```sh
make deploy IMG=<some-registry>/project:tag
```

### Uninstall CRDs
To delete the CRDs from the cluster:

```sh
make uninstall
```

### Undeploy controller
UnDeploy the controller to the cluster:

```sh
make undeploy
```

## Contributing
// TODO(user): Add detailed information on how you would like others to contribute to this project

### How it works
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)

It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster

### Test It Out
1. Install the CRDs into the cluster:

```sh
make install
```

2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):

```sh
make run
```

**NOTE:** You can also run this in one step by running: `make install run`

### Modifying the API definitions
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

```sh
make manifests
```

**NOTE:** Run `make --help` for more information on all potential `make` targets

More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)

## License

Copyright 2022 The Kubernetes authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,47 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ProjectConfigSpec defines the desired state of ProjectConfig
type ProjectConfigSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of ProjectConfig. Edit projectconfig_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// ProjectConfigStatus defines the observed state of ProjectConfig
type ProjectConfigStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ProjectConfig is the Schema for the projectconfigs API
type ProjectConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ProjectConfigSpec `json:"spec,omitempty"`
Status ProjectConfigStatus `json:"status,omitempty"`

// ControllerManagerConfigurationSpec returns the contfigurations for controllers
cfg.ControllerManagerConfigurationSpec `json:",inline"`

ClusterName string `json:"clusterName,omitempty"`
}

//+kubebuilder:object:root=true

// ProjectConfigList contains a list of ProjectConfig
type ProjectConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProjectConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&ProjectConfig{})
SchemeBuilder.Register(&ProjectConfig{}, &ProjectConfigList{})
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ spec:
disable the metrics serving.
type: string
type: object
spec:
description: ProjectConfigSpec defines the desired state of ProjectConfig
properties:
foo:
description: Foo is an example field of ProjectConfig. Edit projectconfig_types.go
to remove/update
type: string
type: object
status:
description: ProjectConfigStatus defines the observed state of ProjectConfig
type: object
syncPeriod:
description: SyncPeriod determines the minimum frequency at which watched
resources are reconciled. A lower period will correct entropy more quickly,
Expand Down Expand Up @@ -174,6 +185,8 @@ spec:
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ spec:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.11.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=10"
- "--v=0"
ports:
- containerPort: 8443
protocol: TCP
name: https
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: config.tutorial.kubebuilder.io/v2
kind: ProjectConfig
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ spec:
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
# TODO(user): Configure the resources accordingly based on the project requirements.
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resources:
limits:
cpu: 200m
memory: 100Mi
cpu: 500m
memory: 128Mi
requests:
cpu: 100m
memory: 20Mi
cpu: 10m
memory: 64Mi
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
Loading

0 comments on commit 97062b2

Please sign in to comment.