Skip to content

Commit

Permalink
Add unique limitador-resource label
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-cattermole committed Aug 17, 2023
1 parent e3d5280 commit 55bd6c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion controllers/limitador_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ var _ = Describe("Limitador controller", func() {
return err == nil
}, timeout, interval).Should(BeTrue())
Expect(createdPdb.Spec.MaxUnavailable).To(Equal(maxUnavailable))
Expect(createdPdb.Spec.Selector.MatchLabels).To(Equal(limitador.Labels()))
Expect(createdPdb.Spec.Selector.MatchLabels).To(Equal(limitador.Labels(limitadorObj)))
})
})

Expand Down
23 changes: 13 additions & 10 deletions pkg/limitador/k8s_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Service(limitador *limitadorv1alpha1.Limitador) *v1.Service {
ObjectMeta: metav1.ObjectMeta{
Name: ServiceName(limitador),
Namespace: limitador.ObjectMeta.Namespace, // TODO: revisit later. For now assume same.
Labels: Labels(),
Labels: Labels(limitador),
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -48,7 +48,7 @@ func Service(limitador *limitadorv1alpha1.Limitador) *v1.Service {
TargetPort: intstr.FromString("grpc"),
},
},
Selector: Labels(),
Selector: Labels(limitador),
ClusterIP: v1.ClusterIPNone,
Type: v1.ServiceTypeClusterIP,
},
Expand All @@ -74,16 +74,16 @@ func Deployment(limitador *limitadorv1alpha1.Limitador, storageConfigSecret *v1.
ObjectMeta: metav1.ObjectMeta{
Name: limitador.ObjectMeta.Name, // TODO: revisit later. For now assume same.
Namespace: limitador.ObjectMeta.Namespace, // TODO: revisit later. For now assume same.
Labels: Labels(),
Labels: Labels(limitador),
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: Labels(),
MatchLabels: Labels(limitador),
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: Labels(),
Labels: Labels(limitador),
},
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down Expand Up @@ -171,7 +171,7 @@ func LimitsConfigMap(limitador *limitadorv1alpha1.Limitador) (*v1.ConfigMap, err
ObjectMeta: metav1.ObjectMeta{
Name: LimitsCMNamePrefix + limitador.Name,
Namespace: limitador.Namespace,
Labels: Labels(),
Labels: Labels(limitador),
},
}, nil
}
Expand All @@ -185,13 +185,13 @@ func PodDisruptionBudget(limitadorObj *limitadorv1alpha1.Limitador) *policyv1.Po
ObjectMeta: metav1.ObjectMeta{
Name: PodDisruptionBudgetName(limitadorObj),
Namespace: limitadorObj.ObjectMeta.Namespace,
Labels: Labels(),
Labels: Labels(limitadorObj),
},
Spec: policyv1.PodDisruptionBudgetSpec{
MaxUnavailable: limitadorObj.Spec.PodDisruptionBudget.MaxUnavailable,
MinAvailable: limitadorObj.Spec.PodDisruptionBudget.MinAvailable,
Selector: &metav1.LabelSelector{
MatchLabels: Labels(),
MatchLabels: Labels(limitadorObj),
},
},
}
Expand All @@ -208,8 +208,11 @@ func ValidatePDB(pdb *policyv1.PodDisruptionBudget) error {
return nil
}

func Labels() map[string]string {
return map[string]string{"app": "limitador"}
func Labels(limitador *limitadorv1alpha1.Limitador) map[string]string {
return map[string]string{
"app": "limitador",
"limitador-resource": limitador.ObjectMeta.Name,
}
}

func deploymentContainerCommand(storage *limitadorv1alpha1.Storage, storageConfigSecret *v1.Secret, rateLimitHeaders *limitadorv1alpha1.RateLimitHeadersType) []string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/limitador/k8s_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ func TestPodDisruptionBudget(t *testing.T) {
limitadorObj := newTestLimitadorObj("my-limitador-instance", "default", nil)
pdb := PodDisruptionBudget(limitadorObj)
assert.DeepEqual(t, pdb.Spec.MaxUnavailable, intStrOne)
assert.DeepEqual(t, pdb.Spec.Selector.MatchLabels, Labels())
assert.DeepEqual(t, pdb.Spec.Selector.MatchLabels, Labels(limitadorObj))
}

0 comments on commit 55bd6c3

Please sign in to comment.