You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/10/07 03:48:14 UTC
[camel-k] 12/13: fix(e2e): Replaces update scale with patch scale
This is an automated email from the ASF dual-hosted git repository.
tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 69ded0727210195e9250b9b81839490ea50e4de6
Author: phantomjinx <p....@phantomjinx.co.uk>
AuthorDate: Mon Oct 3 21:58:53 2022 +0100
fix(e2e): Replaces update scale with patch scale
* The use of UpdateScale is unreliable in producing the well-known error
"the object has been modified; please apply your changes to the latest
version and try again".
* Replacing UpdateScale with PatchScale avoids this error and allows the
test to continue successfully
---
e2e/global/common/scale_integration_test.go | 12 +++++++++---
e2e/support/test_support.go | 7 +++++++
.../versioned/typed/camel/v1/fake/fake_integration.go | 10 ++++++++++
.../clientset/versioned/typed/camel/v1/integration.go | 16 ++++++++++++++++
4 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/e2e/global/common/scale_integration_test.go b/e2e/global/common/scale_integration_test.go
index e9789f2ce..504e374d8 100644
--- a/e2e/global/common/scale_integration_test.go
+++ b/e2e/global/common/scale_integration_test.go
@@ -23,6 +23,7 @@ limitations under the License.
package common
import (
+ "encoding/json"
"fmt"
"testing"
@@ -95,9 +96,14 @@ func TestIntegrationScale(t *testing.T) {
Expect(integrationScale.Spec.Replicas).To(BeNumerically("==", 2))
Expect(integrationScale.Status.Replicas).To(BeNumerically("==", 2))
- // Setter
- integrationScale.Spec.Replicas = 1
- integrationScale, err = camel.CamelV1().Integrations(ns).UpdateScale(TestContext, name, integrationScale, metav1.UpdateOptions{})
+ payload := []PatchUInt32Value{{
+ Op: "replace",
+ Path: "/spec/replicas",
+ Value: 1,
+ }}
+ payloadBytes, _ := json.Marshal(payload)
+
+ integrationScale, err = camel.CamelV1().Integrations(ns).PatchScale(TestContext, name, types.JSONPatchType, payloadBytes, metav1.PatchOptions{})
Expect(err).To(BeNil())
// Check the readiness condition is still truthy as down-scaling
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index d363b620c..7cee2a0b8 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -102,6 +102,13 @@ var NoOlmOperatorImage string
var TestContext context.Context
var testClient client.Client
+// patchUint32Value specifies a patch operation for a uint32.
+type PatchUInt32Value struct {
+ Op string `json:"op"`
+ Path string `json:"path"`
+ Value uint32 `json:"value"`
+}
+
var testLocus *testing.T
func setTestLocus(t *testing.T) {
diff --git a/pkg/client/camel/clientset/versioned/typed/camel/v1/fake/fake_integration.go b/pkg/client/camel/clientset/versioned/typed/camel/v1/fake/fake_integration.go
index 0c729b36c..5efa7b05a 100644
--- a/pkg/client/camel/clientset/versioned/typed/camel/v1/fake/fake_integration.go
+++ b/pkg/client/camel/clientset/versioned/typed/camel/v1/fake/fake_integration.go
@@ -164,3 +164,13 @@ func (c *FakeIntegrations) UpdateScale(ctx context.Context, integrationName stri
}
return obj.(*autoscalingv1.Scale), err
}
+
+func (c *FakeIntegrations) PatchScale(ctx context.Context, integrationName string, pt types.PatchType, data []byte, opts v1.PatchOptions) (result *autoscalingv1.Scale, err error) {
+ obj, err := c.Fake.
+ Invokes(testing.NewPatchSubresourceAction(integrationsResource, c.ns, integrationName, pt, data, "scale"), &autoscalingv1.Scale{})
+
+ if obj == nil {
+ return nil, err
+ }
+ return obj.(*autoscalingv1.Scale), err
+}
diff --git a/pkg/client/camel/clientset/versioned/typed/camel/v1/integration.go b/pkg/client/camel/clientset/versioned/typed/camel/v1/integration.go
index 47b7d98a1..52696b2c8 100644
--- a/pkg/client/camel/clientset/versioned/typed/camel/v1/integration.go
+++ b/pkg/client/camel/clientset/versioned/typed/camel/v1/integration.go
@@ -51,6 +51,7 @@ type IntegrationInterface interface {
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Integration, err error)
GetScale(ctx context.Context, integrationName string, options metav1.GetOptions) (*autoscalingv1.Scale, error)
UpdateScale(ctx context.Context, integrationName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error)
+ PatchScale(ctx context.Context, integrationName string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (result *autoscalingv1.Scale, err error)
IntegrationExpansion
}
@@ -227,3 +228,18 @@ func (c *integrations) UpdateScale(ctx context.Context, integrationName string,
Into(result)
return
}
+
+// PatchScale takes the top resource name and the representation of a scale and patches it. Returns the server's representation of the scale, and an error, if there is any.
+func (c *integrations) PatchScale(ctx context.Context, integrationName string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (result *autoscalingv1.Scale, err error) {
+ result = &autoscalingv1.Scale{}
+ err = c.client.Patch(pt).
+ Namespace(c.ns).
+ Resource("integrations").
+ Name(integrationName).
+ SubResource("scale").
+ VersionedParams(&opts, scheme.ParameterCodec).
+ Body(data).
+ Do(ctx).
+ Into(result)
+ return
+}