Skip to content

Commit

Permalink
Rename sharding labels
Browse files Browse the repository at this point in the history
  • Loading branch information
manno committed May 27, 2024
1 parent bf3bffc commit cc12b3b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions charts/fleet/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ spec:
metadata:
labels:
app: fleet-controller
shard: "{{ . }}"
fleet.cattle.io/shard-id: "{{ . }}"
{{- if empty . }}
shard-default: "true"
fleet.cattle.io/shard-default: "true"
{{- end }}
spec:
containers:
Expand Down
4 changes: 2 additions & 2 deletions charts/fleet/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ spec:
selector:
app: fleet-controller
{{- if empty . }}
shard-default: "true"
fleet.cattle.io/shard-default: "true"
{{- else }}
shard: "{{ . }}"
fleet.cattle.io/shard-id: "{{ . }}"
{{- end }}
---
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion e2e/assets/gitrepo-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: {{ .Name }}
{{- if ne .Shard "" }}
labels:
fleet.cattle.io/shard: {{ .Shard }}
fleet.cattle.io/shard-ref: {{ .Shard }}
{{- end }}

spec:
Expand Down
2 changes: 1 addition & 1 deletion e2e/assets/gitrepo/gitrepo_sharded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: {{.Name}}
labels:
fleet.cattle.io/shard: {{.ShardID}}
fleet.cattle.io/shard-ref: {{.ShardID}}
spec:
repo: {{.Repo}}
branch: {{.Branch}}
Expand Down
4 changes: 2 additions & 2 deletions e2e/assets/metrics/fleetcontroller_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ spec:
selector:
app: fleet-controller
{{- if .IsDefaultShard }}
shard-default: "{{ .IsDefaultShard }}"
fleet.cattle.io/shard-default: "{{ .IsDefaultShard }}"
{{ else }}
shard: {{ .Shard }}
fleet.cattle.io/shard-id: {{ .Shard }}
{{- end }}
ports:
- protocol: TCP
Expand Down
6 changes: 3 additions & 3 deletions e2e/single-cluster/imagescan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ var _ = Describe("Image Scan dynamic tests pushing to ttl.sh", Label("infra-setu
})

func getFleetControllerRestarts(k kubectl.Command, index int) int {
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "shard=",
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "fleet.cattle.io/shard-id=",
"--no-headers",
"-o", fmt.Sprintf("custom-columns=RESTARTS:.status.containerStatuses[%d].restartCount", index))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -200,7 +200,7 @@ func getFleetControllerRestarts(k kubectl.Command, index int) int {
}

func getFleetControllerReady(k kubectl.Command, index int) bool {
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "shard=",
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "fleet.cattle.io/shard-id=",
"--no-headers",
"-o", fmt.Sprintf("custom-columns=RESTARTS:.status.containerStatuses[%d].ready", index))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -214,7 +214,7 @@ func getFleetControllerContainerIndexInPod(k kubectl.Command, container string)
// the fleet controller pod runs 3 containers.
// we need to know the index of the fleet-controller container inside the pod.
// get all the container names, and return the index of the given container name
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "shard=",
out, err := k.Namespace("cattle-fleet-system").Get("pods", "-l", "app=fleet-controller", "-l", "fleet.cattle.io/shard-id=",
"--no-headers", "-o", "custom-columns=RESTARTS:.status.containerStatuses[*].name")
Expect(err).NotTo(HaveOccurred())
out = strings.TrimSuffix(out, "\n")
Expand Down
6 changes: 3 additions & 3 deletions e2e/single-cluster/sharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func()
"-l",
"app=fleet-controller",
"-l",
fmt.Sprintf("shard=%s", shard),
fmt.Sprintf("fleet.cattle.io/shard-id=%s", shard),
"--tail=-1",
)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -82,7 +82,7 @@ var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func()
"-l",
"app=fleet-controller",
"-l",
fmt.Sprintf("shard=%s", s),
fmt.Sprintf("fleet.cattle.io/shard-id=%s", s),
"--tail=100",
)
g.Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -154,7 +154,7 @@ var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func()
"-l",
"app=fleet-controller",
"-l",
fmt.Sprintf("shard=%s", s),
fmt.Sprintf("fleet.cattle.io/shard-id=%s", s),
"--tail=100",
)
Expect(err).ToNot(HaveOccurred())
Expand Down
11 changes: 9 additions & 2 deletions pkg/sharding/sharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

const ShardingLabel string = "fleet.cattle.io/shard"
const (
// ShardingIDLabel is the label key used to identify the shard ID of a controller pod
ShardingIDLabel string = "fleet.cattle.io/shard-id"
// ShardingRefLabel is the label key used by resources to reference the shard ID of a controller
ShardingRefLabel string = "fleet.cattle.io/shard-ref"
// ShardingDefaultLabel is the label key which is set to true on the controller handling unlabeled resources
ShardingDefaultLabel string = "fleet.cattle.io/shard-default"
)

func FilterByShardID(shardID string) predicate.Funcs {
matchesLabel := func(o client.Object) bool {
label, hasLabel := o.GetLabels()[ShardingLabel]
label, hasLabel := o.GetLabels()[ShardingIDLabel]

if shardID == "" {
return !hasLabel
Expand Down

0 comments on commit cc12b3b

Please sign in to comment.