-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[memcached] add CR name length validation
The memcached controller creates StatefulSet for the memcached to run. This adds a StatefulSet pod's label "controller-revision-hash": "<statefulset_name>-<hash>" to the pod. The kubernetes label is restricted under 63 char and the revision hash is an int32, 10 chars + the hyphen. With this the max name must not exceed 52 chars. Depends-On: openstack-k8s-operators/lib-common#532 Jira: https://issues.redhat.com/browse/OSPRH-8063 Signed-off-by: Martin Schuppert <[email protected]>
- Loading branch information
Showing
8 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2023. | ||
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 functional_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports | ||
. "github.com/onsi/gomega" //revive:disable:dot-imports | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("Memcached webhook", func() { | ||
var memcacheName types.NamespacedName | ||
|
||
When("a default Memcache gets created", func() { | ||
BeforeEach(func() { | ||
memcache := CreateMemcachedConfig(namespace, GetDefaultMemcachedSpec()) | ||
memcacheName.Name = memcache.GetName() | ||
memcacheName.Namespace = memcache.GetNamespace() | ||
DeferCleanup(th.DeleteInstance, memcache) | ||
}) | ||
|
||
It("should have created a Memcache", func() { | ||
Eventually(func(_ Gomega) { | ||
GetMemcached(memcacheName) | ||
}, timeout, interval).Should(Succeed()) | ||
}) | ||
}) | ||
|
||
When("a Memcache gets created with a name longer then 52 chars", func() { | ||
It("gets blocked by the webhook and fail", func() { | ||
|
||
raw := map[string]interface{}{ | ||
"apiVersion": "memcached.openstack.org/v1beta1", | ||
"kind": "Memcached", | ||
"metadata": map[string]interface{}{ | ||
"name": "foo-1234567890-1234567890-1234567890-1234567890-1234567890", | ||
"namespace": namespace, | ||
}, | ||
"spec": GetDefaultMemcachedSpec(), | ||
} | ||
|
||
unstructuredObj := &unstructured.Unstructured{Object: raw} | ||
_, err := controllerutil.CreateOrPatch( | ||
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil }) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters