Skip to content

Commit

Permalink
Build common options for agent
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Qiu <[email protected]>
  • Loading branch information
qiujian16 committed Jun 7, 2023
1 parent 6f21760 commit 79e18b6
Show file tree
Hide file tree
Showing 84 changed files with 576 additions and 497 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
- name: install imagebuilder
run: go install github.com/openshift/imagebuilder/cmd/[email protected]
- name: Build images
run: make images
run: IMAGE_TAG=e2e make images
- name: Load images
run: |
kind load docker-image --name=kind quay.io/open-cluster-management/registration-operator:latest
kind load docker-image --name=kind quay.io/open-cluster-management/registration:latest
kind load docker-image --name=kind quay.io/open-cluster-management/work:latest
kind load docker-image --name=kind quay.io/open-cluster-management/placement:latest
kind load docker-image --name=kind quay.io/open-cluster-management/registration-operator:e2e
kind load docker-image --name=kind quay.io/open-cluster-management/registration:e2e
kind load docker-image --name=kind quay.io/open-cluster-management/work:e2e
kind load docker-image --name=kind quay.io/open-cluster-management/placement:e2e
- name: Test E2E
run: |
make test-e2e
IMAGE_TAG=e2e make test-e2e
env:
KUBECONFIG: /home/runner/.kube/config
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ REGISTRATION_IMAGE ?= $(IMAGE_REGISTRY)/registration:$(IMAGE_TAG)
# PLACEMENT_IMAGE can be set in the env to override calculated value
PLACEMENT_IMAGE ?= $(IMAGE_REGISTRY)/placement:$(IMAGE_TAG)
# ADDON_MANAGER_IMAGE can be set in the env to override calculated value
ADDON_MANAGER_IMAGE ?= $(IMAGE_REGISTRY)/addon-manager:$(IMAGE_TAG)
ADDON_MANAGER_IMAGE ?= $(IMAGE_REGISTRY)/addon-manager:latest

$(call build-image,registration,$(REGISTRATION_IMAGE),./build/Dockerfile.registration,.)
$(call build-image,work,$(WORK_IMAGE),./build/Dockerfile.work,.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ spec:
{{ if .HostedMode }}
- "--kubeconfig=/var/run/secrets/hub/kubeconfig"
{{ end }}
imagePullPolicy: Always
resources:
requests:
cpu: 2m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
args:
- "/registration"
- "agent"
- "--cluster-name={{ .ClusterName }}"
- "--spoke-cluster-name={{ .ClusterName }}"
- "--bootstrap-kubeconfig=/spoke/bootstrap/kubeconfig"
{{ if gt (len .RegistrationFeatureGates) 0 }}
{{range .RegistrationFeatureGates}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/hub/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/openshift/library-go/pkg/controller/controllercmd"

"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager"
"open-cluster-management.io/ocm/pkg/version"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/spoke/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/openshift/library-go/pkg/controller/controllercmd"

"open-cluster-management.io/ocm/pkg/registration-operator/operators/klusterlet"
"open-cluster-management.io/ocm/pkg/operator/operators/klusterlet"
"open-cluster-management.io/ocm/pkg/version"
)

Expand Down
64 changes: 64 additions & 0 deletions pkg/common/options/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package options

import (
"fmt"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/spf13/pflag"
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"strings"
)

// AgentOptions is the common agent options
type AgentOptions struct {
SpokeKubeconfigFile string
SpokeClusterName string
Burst int
QPS float32
}

// NewWorkloadAgentOptions returns the flags with default value set
func NewAgentOptions() *AgentOptions {
return &AgentOptions{
QPS: 50,
Burst: 100,
}
}

func (o *AgentOptions) AddFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.SpokeKubeconfigFile, "spoke-kubeconfig", o.SpokeKubeconfigFile,
"Location of kubeconfig file to connect to spoke cluster. If this is not set, will use '--kubeconfig' to build client to connect to the managed cluster.")
flags.StringVar(&o.SpokeClusterName, "spoke-cluster-name", o.SpokeClusterName, "Name of the spoke cluster.")
flags.MarkDeprecated("cluster-name", "use spoke-cluster-name flag")
flags.StringVar(&o.SpokeClusterName, "cluster-name", o.SpokeClusterName,
"Name of the spoke cluster.")
flags.Float32Var(&o.QPS, "spoke-kube-api-qps", o.QPS, "QPS to use while talking with apiserver on spoke cluster.")
flags.IntVar(&o.Burst, "spoke-kube-api-burst", o.Burst, "Burst to use while talking with apiserver on spoke cluster.")
}

// spokeKubeConfig builds kubeconfig for the spoke/managed cluster
func (o *AgentOptions) SpokeKubeConfig(controllerContext *controllercmd.ControllerContext) (*rest.Config, error) {
if o.SpokeKubeconfigFile == "" {
return controllerContext.KubeConfig, nil
}

spokeRestConfig, err := clientcmd.BuildConfigFromFlags("" /* leave masterurl as empty */, o.SpokeKubeconfigFile)
if err != nil {
return nil, fmt.Errorf("unable to load spoke kubeconfig from file %q: %w", o.SpokeKubeconfigFile, err)
}
spokeRestConfig.QPS = o.QPS
spokeRestConfig.Burst = o.Burst
return spokeRestConfig, nil
}

func (o *AgentOptions) Validate() error {
if o.SpokeClusterName == "" {
return fmt.Errorf("cluster name is empty")
}
if errMsgs := apimachineryvalidation.ValidateNamespaceName(o.SpokeClusterName, false); len(errMsgs) > 0 {
return fmt.Errorf("metadata.name format is not correct: %s", strings.Join(errMsgs, ","))
}

return nil
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
opratorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

func NamedCondition(name, reason string, status metav1.ConditionStatus) metav1.Condition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
operatorv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/certrotation"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/certrotation"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
operatorinformers "open-cluster-management.io/api/client/operator/informers/externalversions"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
ocmfeature "open-cluster-management.io/api/feature"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
migrationclient "sigs.k8s.io/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
fakemigrationclient "sigs.k8s.io/kube-storage-version-migrator/pkg/clients/clientset/fake"
migrationclient "sigs.k8s.io/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1"

"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/crdmanager"
"open-cluster-management.io/ocm/pkg/operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/operators/crdmanager"
migrationclient "sigs.k8s.io/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"k8s.io/client-go/kubernetes"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"k8s.io/client-go/rest"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"k8s.io/client-go/kubernetes"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/migrationcontroller"
"open-cluster-management.io/ocm/pkg/operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/migrationcontroller"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
operatorinformers "open-cluster-management.io/api/client/operator/informers/externalversions"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/migrationcontroller"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/migrationcontroller"
)

func TestSync(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
migrationv1alpha1 "sigs.k8s.io/kube-storage-version-migrator/pkg/apis/migration/v1alpha1"
migrationv1alpha1client "sigs.k8s.io/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
operatorv1client "open-cluster-management.io/api/client/operator/clientset/versioned/typed/operator/v1"
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"

"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
operatorinformers "open-cluster-management.io/api/client/operator/informers/externalversions"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
testinghelper "open-cluster-management.io/ocm/pkg/registration-operator/helpers/testing"
testinghelper "open-cluster-management.io/ocm/pkg/operator/helpers/testing"
)

const testClusterManagerName = "testclustermanager"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
corev1informers "k8s.io/client-go/informers/core/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"

"github.com/openshift/library-go/pkg/controller/controllercmd"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
operatorclient "open-cluster-management.io/api/client/operator/clientset/versioned"
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/certrotationcontroller"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/clustermanagercontroller"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/crdstatuccontroller"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/migrationcontroller"
clustermanagerstatuscontroller "open-cluster-management.io/ocm/pkg/registration-operator/operators/clustermanager/controllers/statuscontroller"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/certrotationcontroller"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/clustermanagercontroller"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/crdstatuccontroller"
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/migrationcontroller"
clustermanagerstatuscontroller "open-cluster-management.io/ocm/pkg/operator/operators/clustermanager/controllers/statuscontroller"
)

type Options struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
coreinformer "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"

"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
operatorapiv1 "open-cluster-management.io/api/operator/v1"

"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

type klusterletCleanupController struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
clienttesting "k8s.io/client-go/testing"
"k8s.io/klog/v2"
testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

// TestSyncDelete test cleanup hub deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
workv1client "open-cluster-management.io/api/client/work/clientset/versioned/typed/work/v1"
operatorapiv1 "open-cluster-management.io/api/operator/v1"

"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
operatorapiv1 "open-cluster-management.io/api/operator/v1"
workapiv1 "open-cluster-management.io/api/work/v1"
testingcommon "open-cluster-management.io/ocm/pkg/common/testing"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
testinghelper "open-cluster-management.io/ocm/pkg/registration-operator/helpers/testing"
"open-cluster-management.io/ocm/pkg/operator/helpers"
testinghelper "open-cluster-management.io/ocm/pkg/operator/helpers/testing"
)

type testController struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"k8s.io/apimachinery/pkg/util/version"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/registration-operator/operators/crdmanager"
"open-cluster-management.io/ocm/pkg/operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/operators/crdmanager"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
operatorapiv1 "open-cluster-management.io/api/operator/v1"

"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"k8s.io/client-go/kubernetes"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"k8s.io/client-go/kubernetes"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
"open-cluster-management.io/ocm/manifests"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

// runtimeReconcile ensure all runtime of klusterlet is applied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
operatorv1client "open-cluster-management.io/api/client/operator/clientset/versioned/typed/operator/v1"
operatorinformer "open-cluster-management.io/api/client/operator/informers/externalversions/operator/v1"
operatorlister "open-cluster-management.io/api/client/operator/listers/operator/v1"
"open-cluster-management.io/ocm/pkg/registration-operator/helpers"
"open-cluster-management.io/ocm/pkg/operator/helpers"
)

// SSARReSyncTime is exposed so that integration tests can crank up the controller sync speed.
Expand Down
Loading

0 comments on commit 79e18b6

Please sign in to comment.