Skip to content

Commit

Permalink
add QPS and burst for the agent components
Browse files Browse the repository at this point in the history
Signed-off-by: ZhiweiYin <zyin@redhat.com>
  • Loading branch information
zhiweiyin318 committed Jan 15, 2024
1 parent d6f9e4c commit 7ec86d7
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ spec:
enum:
- Enable
- Disable
kubeAPIBurst:
description: 'KubeAPIBurst indicates the maximum burst of the throttle while talking with apiserver of hub cluster from the spoke cluster. If it is set empty, use the default value: 100'
type: integer
format: int32
default: 100
kubeAPIQPS:
description: 'KubeAPIQPS indicates the maximum QPS while talking with apiserver of hub cluster from the spoke cluster. If it is set empty, use the default value: 50'
type: string
default: "50"
pattern: ^(-?\d+)(.\d+)?$
registrationImagePullSpec:
description: RegistrationImagePullSpec represents the desired image configuration of registration agent. quay.io/open-cluster-management.io/registration:latest will be used if unspecified.
type: string
Expand Down Expand Up @@ -177,6 +187,16 @@ spec:
enum:
- Enable
- Disable
kubeAPIBurst:
description: 'KubeAPIBurst indicates the maximum burst of the throttle while talking with apiserver of hub cluster from the spoke cluster. If it is set empty, use the default value: 100'
type: integer
format: int32
default: 100
kubeAPIQPS:
description: 'KubeAPIQPS indicates the maximum QPS while talking with apiserver of hub cluster from the spoke cluster. If it is set empty, use the default value: 50'
type: string
default: "50"
pattern: ^(-?\d+)(.\d+)?$
workImagePullSpec:
description: WorkImagePullSpec represents the desired image configuration of work agent. quay.io/open-cluster-management.io/work:latest will be used if unspecified.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ spec:
- feature
type: object
type: array
kubeAPIBurst:
default: 100
description: 'KubeAPIBurst indicates the maximum burst of the
throttle while talking with apiserver of hub cluster from the
spoke cluster. If it is set empty, use the default value: 100'
format: int32
type: integer
kubeAPIQPS:
default: "50"
description: 'KubeAPIQPS indicates the maximum QPS while talking
with apiserver of hub cluster from the spoke cluster. If it
is set empty, use the default value: 50'
pattern: ^(-?\d+)(.\d+)?$
type: string
type: object
registrationImagePullSpec:
description: RegistrationImagePullSpec represents the desired image
Expand Down Expand Up @@ -274,6 +288,20 @@ spec:
- feature
type: object
type: array
kubeAPIBurst:
default: 100
description: 'KubeAPIBurst indicates the maximum burst of the
throttle while talking with apiserver of hub cluster from the
spoke cluster. If it is set empty, use the default value: 100'
format: int32
type: integer
kubeAPIQPS:
default: "50"
description: 'KubeAPIQPS indicates the maximum QPS while talking
with apiserver of hub cluster from the spoke cluster. If it
is set empty, use the default value: 50'
pattern: ^(-?\d+)(.\d+)?$
type: string
type: object
workImagePullSpec:
description: WorkImagePullSpec represents the desired image configuration
Expand Down
40 changes: 39 additions & 1 deletion operator/v1/types_klusterlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type KlusterletSpec struct {

// WorkConfiguration contains the configuration of work
// +optional
WorkConfiguration *WorkConfiguration `json:"workConfiguration,omitempty"`
WorkConfiguration *WorkAgentConfiguration `json:"workConfiguration,omitempty"`

// HubApiServerHostAlias contains the host alias for hub api server.
// registration-agent and work-agent will use it to communicate with hub api server.
Expand Down Expand Up @@ -157,6 +157,44 @@ type RegistrationConfiguration struct {
// ManagedCluster when creating only, other actors can update it afterwards.
// +optional
ClusterAnnotations map[string]string `json:"clusterAnnotations,omitempty"`

// KubeAPIQPS indicates the maximum QPS while talking with apiserver of hub cluster from the spoke cluster.
// If it is set empty, use the default value: 50
// +optional
// +kubebuilder:default:="50"
// +kubebuilder:validation:Pattern=^(-?\d+)(.\d+)?$
KubeAPIQPS string `json:"kubeAPIQPS,omitempty"`

// KubeAPIBurst indicates the maximum burst of the throttle while talking with apiserver of hub cluster from the spoke cluster.
// If it is set empty, use the default value: 100
// +optional
// +kubebuilder:default:=100
KubeAPIBurst int32 `json:"kubeAPIBurst,omitempty"`
}

type WorkAgentConfiguration struct {
// FeatureGates represents the list of feature gates for work
// If it is set empty, default feature gates will be used.
// If it is set, featuregate/Foo is an example of one item in FeatureGates:
// 1. If featuregate/Foo does not exist, registration-operator will discard it
// 2. If featuregate/Foo exists and is false by default. It is now possible to set featuregate/Foo=[false|true]
// 3. If featuregate/Foo exists and is true by default. If a cluster-admin upgrading from 1 to 2 wants to continue having featuregate/Foo=false,
// he can set featuregate/Foo=false before upgrading. Let's say the cluster-admin wants featuregate/Foo=false.
// +optional
FeatureGates []FeatureGate `json:"featureGates,omitempty"`

// KubeAPIQPS indicates the maximum QPS while talking with apiserver of hub cluster from the spoke cluster.
// If it is set empty, use the default value: 50
// +optional
// +kubebuilder:default:="50"
// +kubebuilder:validation:Pattern=^(-?\d+)(.\d+)?$
KubeAPIQPS string `json:"kubeAPIQPS,omitempty"`

// KubeAPIBurst indicates the maximum burst of the throttle while talking with apiserver of hub cluster from the spoke cluster.
// If it is set empty, use the default value: 100
// +optional
// +kubebuilder:default:=100
KubeAPIBurst int32 `json:"kubeAPIBurst,omitempty"`
}

const (
Expand Down
23 changes: 22 additions & 1 deletion operator/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions operator/v1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 58 additions & 3 deletions test/integration/api/klusterlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"fmt"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -118,7 +119,7 @@ var _ = Describe("Klusterlet API test with WorkConfiguration", func() {
Name: klusterletName,
},
Spec: operatorv1.KlusterletSpec{
WorkConfiguration: &operatorv1.WorkConfiguration{
WorkConfiguration: &operatorv1.WorkAgentConfiguration{
FeatureGates: []operatorv1.FeatureGate{
{
Feature: "Foo",
Expand All @@ -138,7 +139,7 @@ var _ = Describe("Klusterlet API test with WorkConfiguration", func() {
Name: klusterletName,
},
Spec: operatorv1.KlusterletSpec{
WorkConfiguration: &operatorv1.WorkConfiguration{
WorkConfiguration: &operatorv1.WorkAgentConfiguration{
FeatureGates: []operatorv1.FeatureGate{
{
Feature: "Foo",
Expand All @@ -158,7 +159,7 @@ var _ = Describe("Klusterlet API test with WorkConfiguration", func() {
Name: klusterletName,
},
Spec: operatorv1.KlusterletSpec{
WorkConfiguration: &operatorv1.WorkConfiguration{
WorkConfiguration: &operatorv1.WorkAgentConfiguration{
FeatureGates: []operatorv1.FeatureGate{
{
Feature: "Foo",
Expand All @@ -177,4 +178,58 @@ var _ = Describe("Klusterlet API test with WorkConfiguration", func() {
Expect(klusterlet.Spec.WorkConfiguration.FeatureGates[0].Mode).Should(Equal(operatorv1.FeatureGateModeTypeDisable))
Expect(klusterlet.Spec.WorkConfiguration.FeatureGates[1].Mode).Should(Equal(operatorv1.FeatureGateModeTypeEnable))
})

It("Create a klusterlet with right QPS", func() {

cases := []struct {
qps string
expectErr bool
}{
{
qps: "abc",
expectErr: true,
},
{
qps: "123.abc",
expectErr: true,
},
{
qps: "abc213",
expectErr: true,
},
{
qps: "123",
expectErr: false,
},
{
qps: "123.123",
expectErr: false,
},
{
qps: "100.0",
expectErr: false,
},
}
for _, c := range cases {
suffix := rand.String(5)
klusterletName = fmt.Sprintf("cm-%s", suffix)
klusterlet := &operatorv1.Klusterlet{
ObjectMeta: metav1.ObjectMeta{
Name: klusterletName,
},
Spec: operatorv1.KlusterletSpec{
WorkConfiguration: &operatorv1.WorkAgentConfiguration{
KubeAPIQPS: c.qps,
},
},
}
_, err := operatorClient.OperatorV1().Klusterlets().Create(context.TODO(), klusterlet, metav1.CreateOptions{})
if c.expectErr {
Expect(err).To(HaveOccurred())
Expect(strings.Contains(err.Error(), "is invalid: spec.workConfiguration.kubeAPIQPS:")).To(BeTrue())
} else {
Expect(err).To(BeNil())
}
}
})
})

0 comments on commit 7ec86d7

Please sign in to comment.