Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ issues:
- linters:
- stylecheck
text: "ST1001: should not use dot imports"
path: "pkg/test"
path: "pkg/utils/test"
- linters:
- nolintlint
text: "should be written without leading space"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test-kyverno: $(KYVERNO) ## Run kyverno policy tests.

.PHONY: test-e2e
test-e2e: $(GINKGO) ## Run e2e tests.
ginkgo run --timeout=1h --poll-progress-after=60s --poll-progress-interval=30s --randomize-all --randomize-suites --keep-going --vv $(GINKGO_FLAGS) ./test/e2e/...
$(GINKGO) run --timeout=1h --poll-progress-after=60s --poll-progress-interval=30s --randomize-all --randomize-suites --keep-going --vv $(GINKGO_FLAGS) ./test/e2e/...

.PHONY: skaffold-fix
skaffold-fix: $(SKAFFOLD) ## Upgrade skaffold configuration to the latest apiVersion.
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/config/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func SetDefaults_SharderConfig(obj *SharderConfig) {
}

if obj.GracefulShutdownTimeout == nil {
var defaultGracefulShutdownTimeout = 15 * time.Second
obj.GracefulShutdownTimeout = &metav1.Duration{Duration: defaultGracefulShutdownTimeout}
obj.GracefulShutdownTimeout = &metav1.Duration{Duration: 15 * time.Second}
}
}

Expand Down
127 changes: 127 additions & 0 deletions pkg/apis/config/v1alpha1/defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2025 Tim Ebert.

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.
*/

package v1alpha1_test

import (
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
"k8s.io/utils/ptr"

. "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/config/v1alpha1"
)

var _ = Describe("SharderConfig defaulting", func() {
var obj *SharderConfig

BeforeEach(func() {
obj = &SharderConfig{}
})

Context("ClientConnectionConfiguration", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.ClientConnection).To(Equal(&componentbaseconfigv1alpha1.ClientConnectionConfiguration{
QPS: 100,
Burst: 150,
}))
})
})

Context("LeaderElectionConfiguration", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.LeaderElection).To(Equal(&componentbaseconfigv1alpha1.LeaderElectionConfiguration{
LeaderElect: ptr.To(true),
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
ResourceLock: "leases",
ResourceName: "sharder",
ResourceNamespace: "sharding-system",
}))
})
})

Context("DebuggingConfiguration", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.Debugging).To(Equal(&componentbaseconfigv1alpha1.DebuggingConfiguration{
EnableProfiling: ptr.To(true),
EnableContentionProfiling: ptr.To(false),
}))
})
})

Context("manager settings", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.Health).To(Equal(HealthEndpoint{
BindAddress: ":8081",
}))
Expect(obj.Metrics).To(Equal(MetricsEndpoint{
BindAddress: ":8080",
}))
Expect(obj.GracefulShutdownTimeout).To(Equal(&metav1.Duration{Duration: 15 * time.Second}))
})
})

Context("controller config", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.Controller).To(Equal(Controller{
Sharder: &SharderController{
SyncPeriod: &metav1.Duration{Duration: 5 * time.Minute},
},
}))
})
})

Context("webhook config", func() {
It("should set default values", func() {
SetObjectDefaults_SharderConfig(obj)

Expect(obj.Webhook).To(Equal(Webhook{
Server: &WebhookServer{},
Config: &WebhookConfig{
ClientConfig: &admissionregistrationv1.WebhookClientConfig{
Service: &admissionregistrationv1.ServiceReference{
Namespace: "sharding-system",
Name: "sharder",
},
},
NamespaceSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: "kubernetes.io/metadata.name",
Operator: "NotIn",
Values: []string{"kube-system", "sharding-system"},
}},
},
},
}))
})
})
})
1 change: 1 addition & 0 deletions pkg/apis/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type WebhookConfig struct {
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// ClientConfig configures the webhook configs' target.
// Defaults to a service reference to sharding-system/sharder.
// +optional
ClientConfig *admissionregistrationv1.WebhookClientConfig `json:"clientConfig,omitempty"`
// NamespaceSelector overwrites the webhook configs' default namespaceSelector.
Expand Down
29 changes: 29 additions & 0 deletions pkg/apis/config/v1alpha1/v1alpha1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2025 Tim Ebert.

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.
*/

package v1alpha1_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestV1alpha1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Sharder Config API V1alpha1 Suite")
}
36 changes: 36 additions & 0 deletions pkg/apis/sharding/v1alpha1/constants_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2025 Tim Ebert.

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.
*/

package v1alpha1_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1"
)

var _ = Describe("#LabelShard", func() {
It("should append the ControllerRing name", func() {
Expect(LabelShard("foo")).To(Equal("shard.alpha.sharding.timebertt.dev/foo"))
})
})

var _ = Describe("#LabelDrain", func() {
It("should append the ControllerRing name", func() {
Expect(LabelDrain("foo")).To(Equal("drain.alpha.sharding.timebertt.dev/foo"))
})
})
2 changes: 1 addition & 1 deletion pkg/apis/sharding/v1alpha1/types_controllerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (c *ControllerRing) LabelDrain() string {
return LabelDrain(c.Name)
}

// RingResources returns the the list of resources that are distributed across shards in this ControllerRing.
// RingResources returns the list of resources that are distributed across shards in this ControllerRing.
func (c *ControllerRing) RingResources() []RingResource {
return c.Spec.Resources
}
73 changes: 73 additions & 0 deletions pkg/apis/sharding/v1alpha1/types_controllerring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2025 Tim Ebert.

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.
*/

package v1alpha1_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1"
)

var _ = Describe("ControllerRing", func() {
var ring *ControllerRing

BeforeEach(func() {
ring = &ControllerRing{
ObjectMeta: metav1.ObjectMeta{
Name: "operator",
},
Spec: ControllerRingSpec{
Resources: []RingResource{{
GroupResource: metav1.GroupResource{
Group: "",
Resource: "configmaps",
},
ControlledResources: []metav1.GroupResource{{
Group: "",
Resource: "secrets",
}},
}},
},
}
})

Describe("#LeaseSelector", func() {
It("should return the correct lease selector", func() {
Expect(ring.LeaseSelector().String()).To(Equal("alpha.sharding.timebertt.dev/controllerring=operator"))
})
})

Describe("#LabelShard", func() {
It("should append the ControllerRing name", func() {
Expect(ring.LabelShard()).To(Equal("shard.alpha.sharding.timebertt.dev/operator"))
})
})

Describe("#LabelDrain", func() {
It("should append the ControllerRing name", func() {
Expect(ring.LabelDrain()).To(Equal("drain.alpha.sharding.timebertt.dev/operator"))
})
})

Describe("#RingResources", func() {
It("should return the specified resources", func() {
Expect(ring.RingResources()).To(Equal(ring.Spec.Resources))
})
})
})
29 changes: 29 additions & 0 deletions pkg/apis/sharding/v1alpha1/v1alpha1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2025 Tim Ebert.

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.
*/

package v1alpha1_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestV1alpha1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Sharding API V1alpha1 Suite")
}
3 changes: 1 addition & 2 deletions pkg/sharding/leases/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func (s Shards) IDs() []string {
func ToShards(leases []coordinationv1.Lease, now time.Time) Shards {
shards := make(Shards, 0, len(leases))
for _, lease := range leases {
l := lease
shards = append(shards, ToShard(&l, now))
shards = append(shards, ToShard(&lease, now))
}
return shards
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

shardingv1alpha1 "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1"
"github.com/timebertt/kubernetes-controller-sharding/pkg/test/komega"
"github.com/timebertt/kubernetes-controller-sharding/pkg/utils/test/komega"
)

func TestE2E(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

shardingv1alpha1 "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1"
"github.com/timebertt/kubernetes-controller-sharding/pkg/test"
. "github.com/timebertt/kubernetes-controller-sharding/pkg/test/komega"
. "github.com/timebertt/kubernetes-controller-sharding/pkg/test/matchers"
"github.com/timebertt/kubernetes-controller-sharding/pkg/utils/test"
. "github.com/timebertt/kubernetes-controller-sharding/pkg/utils/test/komega"
. "github.com/timebertt/kubernetes-controller-sharding/pkg/utils/test/matchers"
)

var _ = Describe("Example Shard", Label("example"), Ordered, func() {
Expand Down
4 changes: 1 addition & 3 deletions webhosting-operator/cmd/experiment/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ func main() {
}
cmd.AddGroup(&group)

for _, s := range experiment.GetAllScenarios() {
scenario := s

for _, scenario := range experiment.GetAllScenarios() {
cmd.AddCommand(&cobra.Command{
Use: scenario.Name(),
Short: scenario.Description(),
Expand Down
4 changes: 1 addition & 3 deletions webhosting-operator/pkg/metrics/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func (e *ThemeExporter) Collect(ch chan<- prometheus.Metric) {
return
}

for _, item := range themeList.Items {
theme := item

for _, theme := range themeList.Items {
staticLabels := generateThemeStaticLabels(&theme)

for _, desc := range themeMetrics {
Expand Down
Loading
Loading