Validate that SGDbOps and SGBackup names do not generate too long names
Summary
When creating an SGDbOps
the name is not validated if it is too long and it is created anyway (this apply to SGBackup
too).
Current Behaviour
The Job is created and the reconciliation cycle fails for the whole cluster
Steps to reproduce
- Create an
SGCluster
with namestackgres
- Create a pgbench benchmark
SGDbOps
with namesuper-very-long-benchmark-with-a-long-name
Expected Behaviour
The SGDbOps
is not created and a validation error telling the name of the resource is too long (specifying maximum length) should be returned.
Possible Solution
Create a validation for the SGDbOps
and SGBackup
CRs in order to check if the name is too long and return an error is so.
Environment
- StackGres version: 1.0.0-beta3-SNAPSHOT
- Kubernetes version: ?
- Cloud provider or hardware configuration: ?
Relevant logs and/or screenshots
2021-07-29 09:52:31,133 INFO [io.st.reconciliator] (ReconciliationShceduler) Cluster default/stackgres it's not up to date. Reconciling
2021-07-29 09:52:31,133 INFO [io.st.reconciliator] (ReconciliationShceduler) Creating resource super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0 of kind: Job
2021-07-29 09:52:31,143 ERROR [io.st.reconciliator] (ReconciliationShceduler) Reconciliation of cluster default/stackgres failed: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://10.96.0.1/apis/batch/v1/namespaces/default/jobs. Message: Job.batch "super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0" is invalid: spec.template.labels: Invalid value: "super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0": must be no more than 63 characters. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=spec.template.labels, message=Invalid value: "super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0": must be no more than 63 characters, reason=FieldValueInvalid, additionalProperties={})], group=batch, kind=Job, name=super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Job.batch "super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0" is invalid: spec.template.labels: Invalid value: "super-very-long-benchmark-with-a-long-name-benchmark-ac64fae569624854-0": must be no more than 63 characters, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:639)
at io.fabric8.kubernetes.client.dsl.base.OperationSupport.assertResponseCode(OperationSupport.java:578)
at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:543)
at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:504)
at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleCreate(OperationSupport.java:292)
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.handleCreate(BaseOperation.java:893)
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.create(BaseOperation.java:372)
at io.fabric8.kubernetes.client.dsl.base.BaseOperation.create(BaseOperation.java:86)
at io.stackgres.operator.conciliation.AbstractReconciliationHandler.lambda$create$0(AbstractReconciliationHandler.java:30)
at io.stackgres.common.KubernetesClientFactory.withNewClient(KubernetesClientFactory.java:18)
at io.stackgres.operator.app.KubernetesClientProvider_ClientProxy.withNewClient(KubernetesClientProvider_ClientProxy.zig:157)
at io.stackgres.operator.conciliation.AbstractReconciliationHandler.create(AbstractReconciliationHandler.java:28)
at io.stackgres.operator.conciliation.cluster.ClusterDefaultReconciliationHandler_ClientProxy.create(ClusterDefaultReconciliationHandler_ClientProxy.zig:284)
at io.stackgres.operator.conciliation.cluster.ClusterHandlerDelegator.create(ClusterHandlerDelegator.java:38)
at io.stackgres.operator.conciliation.cluster.ClusterHandlerDelegator_ClientProxy.create(ClusterHandlerDelegator_ClientProxy.zig:253)
at io.stackgres.operator.conciliation.StackGresReconciliator.lambda$reconcile$0(StackGresReconciliator.java:51)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at io.stackgres.operator.conciliation.StackGresReconciliator.lambda$reconcile$3(StackGresReconciliator.java:47)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at io.stackgres.operator.conciliation.StackGresReconciliator.reconcile(StackGresReconciliator.java:35)
at io.stackgres.operator.conciliation.cluster.ClusterReconciliator_ClientProxy.reconcile(ClusterReconciliator_ClientProxy.zig:126)
at io.stackgres.operator.app.ReconciliationClockImpl.reconcile(ReconciliationClockImpl.java:30)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Edited by Matteo Melli