Skip to content

Commit

Permalink
fix: unset metadatada validate reserved keys (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvicentin authored Jun 11, 2024
1 parent 6f21905 commit 9e194ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 9 additions & 0 deletions internal/pkg/rpaas/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ func (m *k8sRpaasManager) UnsetMetadata(ctx context.Context, instanceName string
if err != nil {
return err
}

if err = validateMetadata(metadata.Labels); err != nil {
return err
}

if err = validateMetadata(metadata.Annotations); err != nil {
return err
}

originalInstance := instance.DeepCopy()

if metadata.Labels != nil {
Expand Down
26 changes: 22 additions & 4 deletions internal/pkg/rpaas/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Test_k8sRpaasManager_UnsetMetadata(t *testing.T) {
},
},
{
name: "unset invalid label",
name: "unset label that doesn't exist",
objMeta: metav1.ObjectMeta{
Name: "my-instance",
Namespace: "rpaasv2",
Expand All @@ -170,21 +170,39 @@ func Test_k8sRpaasManager_UnsetMetadata(t *testing.T) {
},
expectedErr: "label \"invalid-label\" not found in instance \"my-instance\"",
},
{
name: "unset invalid label",
objMeta: metav1.ObjectMeta{
Name: "my-instance",
Namespace: "rpaasv2",
Labels: map[string]string{
"rpaas_instance": "my-instance",
"rpaas_service": "my-service",
},
},
meta: clientTypes.Metadata{
Labels: []clientTypes.MetadataItem{
{Name: "rpaas_instance"},
},
},
expectedErr: "metadata key \"rpaas_instance\" is reserved",
},
{
name: "unset invalid annotation",
objMeta: metav1.ObjectMeta{
Name: "my-instance",
Namespace: "rpaasv2",
Annotations: map[string]string{
"my-annotation": "my-annotation-value",
"my-annotation": "my-annotation-value",
"rpaas.extensions.tsuru.io/tags": "my-tag=my-value",
},
},
meta: clientTypes.Metadata{
Annotations: []clientTypes.MetadataItem{
{Name: "invalid-annotation"},
{Name: "rpaas.extensions.tsuru.io/tags"},
},
},
expectedErr: "annotation \"invalid-annotation\" not found in instance \"my-instance\"",
expectedErr: "metadata key \"rpaas.extensions.tsuru.io/tags\" is reserved",
},
}

Expand Down

0 comments on commit 9e194ab

Please sign in to comment.