Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,13 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet local-unit-test integration-test## Run tests.

##
## workaround to bypass the pkg/controllers/workv1alpha1 tests failure
## rollout controller tests need a bit longer to complete, so we increase the timeout
##
# Set up the timeout parameters as some of the test lengths have exceeded the default 10 minute mark.
# Set up the timeout parameters as some of the tests (rollout controller) lengths have exceeded the default 10 minute mark.
# TO-DO (chenyu1): enable parallelization for single package integration tests.
.PHONY: local-unit-test
local-unit-test: $(ENVTEST) ## Run tests.
export CGO_ENABLED=1 && \
export KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" && \
go test ./pkg/controllers/workv1alpha1 -race -coverprofile=ut-coverage.xml -covermode=atomic -v && \
go test `go list ./pkg/... ./cmd/... | grep -v pkg/controllers/workv1alpha1` -race -coverpkg=./... -coverprofile=ut-coverage.xml -covermode=atomic -v -timeout=20m
go test `go list ./pkg/... ./cmd/...` -race -coverpkg=./... -coverprofile=ut-coverage.xml -covermode=atomic -v -timeout=20m

.PHONY: integration-test
integration-test: $(ENVTEST) ## Run tests.
Expand Down
2 changes: 0 additions & 2 deletions cmd/hubagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"

fleetnetworkingv1alpha1 "go.goms.io/fleet-networking/api/v1alpha1"

Expand Down Expand Up @@ -70,7 +69,6 @@ const (

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(workv1alpha1.AddToScheme(scheme))
utilruntime.Must(placementv1beta1.AddToScheme(scheme))
utilruntime.Must(clusterv1beta1.AddToScheme(scheme))
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
Expand Down
1 change: 1 addition & 0 deletions cmd/hubagent/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Options struct {
// RateLimiterOpts is the ratelimit parameters for the work queue
RateLimiterOpts RateLimitOptions
// EnableV1Alpha1APIs enables the agents to watch the v1alpha1 CRs.
// TODO(weiweng): remove this field soon. Only kept for backward compatibility.
EnableV1Alpha1APIs bool
// EnableV1Beta1APIs enables the agents to watch the v1beta1 CRs.
EnableV1Beta1APIs bool
Expand Down
29 changes: 7 additions & 22 deletions cmd/memberagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"

clusterv1beta1 "github.com/kubefleet-dev/kubefleet/apis/cluster/v1beta1"
placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
imcv1beta1 "github.com/kubefleet-dev/kubefleet/pkg/controllers/internalmembercluster/v1beta1"
"github.com/kubefleet-dev/kubefleet/pkg/controllers/workapplier"
workv1alpha1controller "github.com/kubefleet-dev/kubefleet/pkg/controllers/workv1alpha1"
"github.com/kubefleet-dev/kubefleet/pkg/propertyprovider"
"github.com/kubefleet-dev/kubefleet/pkg/propertyprovider/azure"
"github.com/kubefleet-dev/kubefleet/pkg/utils"
Expand All @@ -77,9 +75,10 @@ var (
metricsAddr = flag.String("metrics-bind-address", ":8090", "The address the metric endpoint binds to.")
enableLeaderElection = flag.Bool("leader-elect", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
leaderElectionNamespace = flag.String("leader-election-namespace", "kube-system", "The namespace in which the leader election resource will be created.")
enableV1Alpha1APIs = flag.Bool("enable-v1alpha1-apis", true, "If set, the agents will watch for the v1alpha1 APIs.")
enableV1Beta1APIs = flag.Bool("enable-v1beta1-apis", false, "If set, the agents will watch for the v1beta1 APIs.")
leaderElectionNamespace = flag.String("leader-election-namespace", "kube-system", "The namespace in which the leader election resource will be created.")
// TODO(weiweng): only keep enableV1Alpha1APIs for backward compatibility with helm charts. Remove soon.
enableV1Alpha1APIs = flag.Bool("enable-v1alpha1-apis", false, "If set, the agents will watch for the v1alpha1 APIs. This is deprecated and will be removed soon.")
enableV1Beta1APIs = flag.Bool("enable-v1beta1-apis", true, "If set, the agents will watch for the v1beta1 APIs.")
propertyProvider = flag.String("property-provider", "none", "The property provider to use for the agent.")
region = flag.String("region", "", "The region where the member cluster resides.")
cloudConfigFile = flag.String("cloud-config", "/etc/kubernetes/provider/config.json", "The path to the cloud cloudconfig file.")
Expand Down Expand Up @@ -112,7 +111,6 @@ func init() {
klog.InitFlags(nil)

utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(workv1alpha1.AddToScheme(scheme))
utilruntime.Must(clusterv1beta1.AddToScheme(scheme))
utilruntime.Must(placementv1beta1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
Expand Down Expand Up @@ -358,22 +356,9 @@ func Start(ctx context.Context, hubCfg, memberConfig *rest.Config, hubOpts, memb
discoverClient := discovery.NewDiscoveryClientForConfigOrDie(memberConfig)

if *enableV1Alpha1APIs {
gvk := workv1alpha1.SchemeGroupVersion.WithKind(workv1alpha1.AppliedWorkKind)
if err = utils.CheckCRDInstalled(discoverClient, gvk); err != nil {
klog.ErrorS(err, "unable to find the required CRD", "GVK", gvk)
return err
}
// create the work controller, so we can pass it to the internal member cluster reconciler
workController := workv1alpha1controller.NewApplyWorkReconciler(
hubMgr.GetClient(),
spokeDynamicClient,
memberMgr.GetClient(),
restMapper, hubMgr.GetEventRecorderFor("work_controller"), 5, targetNS)

if err = workController.SetupWithManager(hubMgr); err != nil {
klog.ErrorS(err, "Failed to create v1alpha1 controller", "controller", "work")
return err
}
// TODO(weiweng): keeping v1alpha1 APIs for backward compatibility with helm charts. Remove soon.
klog.Error("v1alpha1 APIs are no longer supported. Please switch to v1beta1 APIs")
return errors.New("v1alpha1 APIs are no longer supported. Please switch to v1beta1 APIs")
}

if *enableV1Beta1APIs {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/Azure/karpenter-provider-azure v1.5.1
github.com/crossplane/crossplane-runtime v1.17.0
github.com/evanphx/json-patch/v5 v5.9.11
github.com/go-logr/logr v1.4.3
github.com/google/go-cmp v0.7.0
github.com/onsi/ginkgo/v2 v2.23.4
github.com/onsi/gomega v1.37.0
Expand Down Expand Up @@ -38,7 +37,6 @@ require (
sigs.k8s.io/cloud-provider-azure/pkg/azclient v0.5.20
sigs.k8s.io/cluster-inventory-api v0.0.0-20240730014211-ef0154379848
sigs.k8s.io/controller-runtime v0.20.4
sigs.k8s.io/work-api v0.0.0-20220407021756-586d707fdb2c
)

require (
Expand All @@ -65,6 +63,7 @@ require (
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+Z
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/Azure/k8s-work-api v0.5.0 h1:DVOBt68NFTEVVV+vzz82WdTm4lroXuMd9ktfrfb/kU0=
github.com/Azure/k8s-work-api v0.5.0/go.mod h1:CQiDOlNvMeKvGVer80PtvbW9X1cXq7EID9aMXyxkqPU=
github.com/Azure/karpenter-provider-azure v1.5.1 h1:CH92k7EgLyufVk16c4EsCTUJKrVBBgbWJg85sjbQAHE=
github.com/Azure/karpenter-provider-azure v1.5.1/go.mod h1:Sc2rQ+qqzv9J1Wr9jTpTpzDYsy0MJoNfqPromvH87n8=
github.com/Azure/msi-dataplane v0.4.3 h1:dWPWzY4b54tLIR9T1Q014Xxd/1DxOsMIp6EjRFAJlQY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"

clusterv1beta1 "github.com/kubefleet-dev/kubefleet/apis/cluster/v1beta1"
placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
Expand Down Expand Up @@ -71,8 +70,6 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
err = clusterv1beta1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
err = workv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme
By("construct the k8s client")
Expand Down
12 changes: 0 additions & 12 deletions pkg/controllers/placement/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"

fleetv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1"
"github.com/kubefleet-dev/kubefleet/pkg/utils"
Expand Down Expand Up @@ -497,17 +496,6 @@ func generateRawContent(object *unstructured.Unstructured) ([]byte, error) {
return rawContent, nil
}

// generateManifest creates a manifest from the unstructured obj.
func generateManifest(object *unstructured.Unstructured) (*workv1alpha1.Manifest, error) {
rawContent, err := generateRawContent(object)
if err != nil {
return nil, err
}
return &workv1alpha1.Manifest{
RawExtension: runtime.RawExtension{Raw: rawContent},
}, nil
}

// generateResourceContent creates a resource content from the unstructured obj.
func generateResourceContent(object *unstructured.Unstructured) (*fleetv1beta1.ResourceContent, error) {
rawContent, err := generateRawContent(object)
Expand Down
Loading
Loading