Skip to content

Commit 1f62861

Browse files
authored
Rename example shard to checksum-controller (#507)
1 parent 027261f commit 1f62861

File tree

18 files changed

+149
-150
lines changed

18 files changed

+149
-150
lines changed

.github/workflows/images.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# prepare .ko.yaml to inject build settings into all images
3636
entrypoints=(
3737
./cmd/sharder
38-
./cmd/shard
38+
./cmd/checksum-controller
3939
./webhosting-operator/cmd/experiment
4040
./webhosting-operator/cmd/webhosting-operator
4141
)

.run/shard (kind).run.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="shard (kind)" type="GoApplicationRunConfiguration" factoryName="Go Application">
2+
<configuration default="false" name="checksum-controller (kind)" type="GoApplicationRunConfiguration" factoryName="Go Application">
33
<module name="kubernetes-controller-sharding" />
44
<working_directory value="$PROJECT_DIR$" />
5-
<parameters value="--zap-log-level=debug --shard=shard-host --lease-namespace=default" />
5+
<parameters value="--zap-log-level=debug --shard-name=checksum-controller-host --lease-namespace=default" />
66
<envs>
77
<env name="KUBECONFIG" value="$PROJECT_DIR$/hack/kind_kubeconfig.yaml" />
88
</envs>
99
<kind value="PACKAGE" />
10-
<package value="github.com/timebertt/kubernetes-controller-sharding/cmd/shard" />
10+
<package value="github.com/timebertt/kubernetes-controller-sharding/cmd/checksum-controller" />
1111
<directory value="$PROJECT_DIR$" />
1212
<filePath value="$PROJECT_DIR$/webhosting-operator/cmd/experiment/main.go" />
1313
<method v="2" />
1414
</configuration>
15-
</component>
15+
</component>

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
44
TAG ?= latest
55
GHCR_REPO ?= ghcr.io/timebertt/kubernetes-controller-sharding
66
SHARDER_IMG ?= $(GHCR_REPO)/sharder:$(TAG)
7-
SHARD_IMG ?= $(GHCR_REPO)/shard:$(TAG)
7+
CHECKSUM_CONTROLLER_IMG ?= $(GHCR_REPO)/checksum-controller:$(TAG)
88
WEBHOSTING_OPERATOR_IMG ?= $(GHCR_REPO)/webhosting-operator:$(TAG)
99
EXPERIMENT_IMG ?= $(GHCR_REPO)/experiment:$(TAG)
1010

@@ -142,20 +142,20 @@ run: $(KUBECTL) generate-fast ## Run the sharder from your host and deploy prere
142142
$(KUBECTL) apply --server-side --force-conflicts -k hack/config/certificates/host
143143
go run ./cmd/sharder --config=hack/config/sharder/host/config.yaml --zap-log-level=debug
144144

145-
SHARD_NAME ?= shard-$(shell tr -dc bcdfghjklmnpqrstvwxz2456789 </dev/urandom | head -c 8)
145+
SHARD_NAME ?= checksum-controller-$(shell tr -dc bcdfghjklmnpqrstvwxz2456789 </dev/urandom | head -c 8)
146146

147-
.PHONY: run-shard
148-
run-shard: $(KUBECTL) ## Run a shard from your host and deploy prerequisites.
149-
$(KUBECTL) apply --server-side --force-conflicts -k hack/config/shard/controllerring
150-
go run ./cmd/shard --shard=$(SHARD_NAME) --lease-namespace=default --zap-log-level=debug
147+
.PHONY: run-checksum-controller
148+
run-checksum-controller: $(KUBECTL) ## Run checksum-controller from your host and deploy prerequisites.
149+
$(KUBECTL) apply --server-side --force-conflicts -k hack/config/checksum-controller/controllerring
150+
go run ./cmd/checksum-controller --shard-name=$(SHARD_NAME) --lease-namespace=default --zap-log-level=debug
151151

152152
PUSH ?= false
153153
images: export KO_DOCKER_REPO = $(GHCR_REPO)
154154

155155
.PHONY: images
156156
images: $(KO) ## Build and push container images using ko.
157157
$(KO) build --push=$(PUSH) --sbom none --base-import-paths -t $(TAG) --platform linux/amd64,linux/arm64 \
158-
./cmd/sharder ./cmd/shard ./webhosting-operator/cmd/webhosting-operator
158+
./cmd/sharder ./cmd/checksum-controller ./webhosting-operator/cmd/webhosting-operator
159159

160160
##@ Deployment
161161

@@ -182,7 +182,7 @@ up dev: export SKAFFOLD_TAIL ?= true
182182

183183
.PHONY: deploy
184184
deploy: $(SKAFFOLD) $(KUBECTL) $(YQ) ## Build all images and deploy everything to K8s cluster specified in $KUBECONFIG.
185-
$(SKAFFOLD) deploy -i $(SHARDER_IMG) -i $(SHARD_IMG) -i $(WEBHOSTING_OPERATOR_IMG) -i $(EXPERIMENT_IMG)
185+
$(SKAFFOLD) deploy -i $(SHARDER_IMG) -i $(CHECKSUM_CONTROLLER_IMG) -i $(WEBHOSTING_OPERATOR_IMG) -i $(EXPERIMENT_IMG)
186186

187187
.PHONY: up
188188
up: $(SKAFFOLD) $(KUBECTL) $(YQ) ## Build all images, deploy everything to K8s cluster specified in $KUBECONFIG, start port-forward and tail logs.

cmd/shard/main.go renamed to cmd/checksum-controller/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ func main() {
4848
opts := newOptions()
4949

5050
cmd := &cobra.Command{
51-
Use: "shard",
52-
Short: "Run an example shard",
53-
Long: `The shard command runs an example shard that fulfills the requirements of a controller that supports sharding.
51+
Use: "checksum-controller",
52+
Short: "Run an example sharded controller",
53+
Long: `The checksum-controller is an example for implementing the controller requirements for sharding.
5454
For this, it creates a shard Lease object and renews it periodically.
55-
It also starts a controller for ConfigMaps that are assigned to the shard and handles the drain operation as expected.
55+
It also starts a controller for Secrets that are assigned to the shard and handles the drain operation as expected.
5656
See https://github.com/timebertt/kubernetes-controller-sharding/blob/main/docs/implement-sharding.md for more details.
57-
This is basically a lightweight example controller which is useful for developing the sharding components without actually
58-
running a full controller that complies with the sharding requirements.`,
57+
This example sharded controller is also useful for developing the sharding components.`,
5958

6059
Args: cobra.NoArgs,
6160
SilenceErrors: true,
@@ -92,14 +91,14 @@ func newOptions() *options {
9291
TimeEncoder: zapcore.ISO8601TimeEncoder,
9392
},
9493

95-
controllerRingName: "example",
94+
controllerRingName: "checksum-controller",
9695
}
9796
}
9897

9998
func (o *options) AddFlags(fs *pflag.FlagSet) {
10099
fs.StringVar(&o.controllerRingName, "controllerring", o.controllerRingName, "Name of the ControllerRing the shard belongs to.")
101100
fs.StringVar(&o.leaseNamespace, "lease-namespace", o.leaseNamespace, "Namespace to use for the shard lease. Defaults to the pod's namespace if running in-cluster.")
102-
fs.StringVar(&o.shardName, "shard", o.shardName, "Name of the shard. Defaults to the instance's hostname.")
101+
fs.StringVar(&o.shardName, "shard-name", o.shardName, "Name of the shard. Defaults to the instance's hostname.")
103102

104103
zapFlagSet := flag.NewFlagSet("zap", flag.ContinueOnError)
105104
o.zapOptions.BindFlags(zapFlagSet)
@@ -154,11 +153,11 @@ func (o *options) run(ctx context.Context) error {
154153

155154
// FILTERED WATCH CACHE
156155
Cache: cache.Options{
157-
// This shard only acts on objects in the default namespace.
156+
// This controller only acts on objects in the default namespace.
158157
DefaultNamespaces: map[string]cache.Config{metav1.NamespaceDefault: {}},
159158
// Configure cache to only watch objects that are assigned to this shard.
160-
// This shard only watches sharded objects, so we can configure the label selector on the cache's global level.
161-
// If your shard watches sharded objects as well as non-sharded objects, use cache.Options.ByObject to configure
159+
// This controller only watches sharded objects, so we can configure the label selector on the cache's global level.
160+
// If your controller watches sharded objects as well as non-sharded objects, use cache.Options.ByObject to configure
162161
// the label selector on object level.
163162
DefaultLabelSelector: labels.SelectorFromSet(labels.Set{
164163
shardingv1alpha1.LabelShard(o.controllerRingName): shardLease.Identity(),
File renamed without changes.

docs/development.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Note that you might need to push images to a remote registry though.
2626
The development setup reuses the deployment manifests of the main sharding components developed in this repository, located in [`config`](../config).
2727
See [Install the Sharding Components](installation.md).
2828

29-
It also includes the [example shard](../pkg/shard) (see [Implement Sharding in Your Controller](implement-sharding.md)) and the [webhosting-operator](../webhosting-operator/README.md) (see [Evaluating the Sharding Mechanism](evaluation.md)).
29+
It also includes the [checksum-controller](../cmd/checksum-controller) as an example sharded controller (see [Implement Sharding in Your Controller](implement-sharding.md)) and the [webhosting-operator](../webhosting-operator/README.md) (see [Evaluating the Sharding Mechanism](evaluation.md)).
3030

3131
Apart from this, the development setup also includes some external components, located in [`hack/config`](../hack/config).
3232
This includes [cert-manager](https://cert-manager.io/), [ingress-nginx](https://kubernetes.github.io/ingress-nginx/), [kube-prometheus](https://github.com/prometheus-operator/kube-prometheus), [kyverno](https://kyverno.io/), and [parca](https://parca.dev/).
@@ -83,29 +83,29 @@ Assuming a fresh kind cluster:
8383
make run
8484
```
8585

86-
Now, create the `example` `ControllerRing` and run a local shard:
86+
Now, create the `ControllerRing` and run a local `checksum-controller`:
8787

8888
```bash
89-
make run-shard
89+
make run-checksum-controller
9090
```
9191

9292
You should see that the shard successfully announced itself to the sharder:
9393

9494
```bash
9595
$ kubectl get lease -L alpha.sharding.timebertt.dev/controllerring,alpha.sharding.timebertt.dev/state
96-
NAME HOLDER AGE CONTROLLERRING STATE
97-
shard-5pv57c6c shard-5pv57c6c 18s example ready
96+
NAME HOLDER AGE CONTROLLERRING STATE
97+
checksum-controller-lhrlt6h4 checksum-controller-lhrlt6h4 6s checksum-controller ready
9898

9999
$ kubectl get controllerring
100-
NAME READY AVAILABLE SHARDS AGE
101-
example True 1 1 34s
100+
NAME READY AVAILABLE SHARDS AGE
101+
checksum-controller True 1 1 13s
102102
```
103103

104-
Running the shard locally gives you the option to test non-graceful termination, i.e., a scenario where the shard fails to renew its lease in time.
104+
Running the `checksum-controller` locally gives you the option to test non-graceful termination, i.e., a scenario where the shard fails to renew its lease in time.
105105
Simply press `Ctrl-C` twice:
106106

107107
```bash
108-
make run-shard
108+
make run-checksum-controller
109109
...
110110
^C2023-11-24T15:16:50.948+0100 INFO Shutting down gracefully in 2 seconds, send another SIGINT or SIGTERM to shutdown non-gracefully
111111
^Cexit status 1
@@ -114,18 +114,18 @@ make run-shard
114114
## Testing the Sharding Setup
115115

116116
Independent of the used setup (skaffold-based or running on the host machine), you should be able to create sharded `Secrets` in the `default` namespace as configured in the `example` `ControllerRing`.
117-
The `ConfigMaps` created by the example shard controller should be assigned to the same shard as the owning `Secret`:
117+
The `ConfigMaps` created by the `checksum-controller` should be assigned to the same shard as the owning `Secret`:
118118

119119
```bash
120120
$ kubectl create secret generic foo --from-literal foo=bar
121121
secret/foo created
122122

123-
$ kubectl get cm,secret -L shard.alpha.sharding.timebertt.dev/example
124-
NAME DATA AGE EXAMPLE
125-
configmap/checksums-foo 1 1s shard-5pv57c6c
123+
$ kubectl get cm,secret -L shard.alpha.sharding.timebertt.dev/checksum-controller
124+
NAME DATA AGE CHECKSUM-CONTROLLER
125+
configmap/checksums-foo 1 1s checksum-controller-lhrlt6h4
126126

127-
NAME TYPE DATA AGE EXAMPLE
128-
secret/foo Opaque 1 1s shard-5pv57c6c
127+
NAME TYPE DATA AGE CHECKSUM-CONTROLLER
128+
secret/foo Opaque 1 1s checksum-controller-lhrlt6h4
129129
```
130130

131131
## Monitoring

0 commit comments

Comments
 (0)