@@ -4,9 +4,11 @@ package api
44import (
55 "context"
66 "fmt"
7+ apierrors "k8s.io/apimachinery/pkg/api/errors"
78
89 . "github.com/onsi/ginkgo"
910 . "github.com/onsi/gomega"
11+ v1 "k8s.io/api/core/v1"
1012 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1113 "k8s.io/apimachinery/pkg/util/rand"
1214 operatorv1 "open-cluster-management.io/api/operator/v1"
@@ -410,3 +412,180 @@ var _ = Describe("ClusterManager API test with WorkConfiguration", func() {
410412 Expect (clusterManager .Spec .WorkConfiguration .FeatureGates [1 ].Mode ).Should (Equal (operatorv1 .FeatureGateModeTypeEnable ))
411413 })
412414})
415+
416+ var _ = Describe ("ClusterManager v1 Enhanced API test" , func () {
417+ var clusterManagerName string
418+
419+ BeforeEach (func () {
420+ suffix := rand .String (5 )
421+ clusterManagerName = fmt .Sprintf ("cm-enhanced-%s" , suffix )
422+ })
423+
424+ AfterEach (func () {
425+ err := operatorClient .OperatorV1 ().ClusterManagers ().Delete (context .TODO (), clusterManagerName , metav1.DeleteOptions {})
426+ if ! apierrors .IsForbidden (err ) {
427+ Expect (err ).ToNot (HaveOccurred ())
428+ }
429+ })
430+
431+ Context ("ClusterManager comprehensive configuration validation" , func () {
432+ It ("should handle complete configuration with all optional fields" , func () {
433+ clusterManager := & operatorv1.ClusterManager {
434+ ObjectMeta : metav1.ObjectMeta {
435+ Name : clusterManagerName ,
436+ },
437+ Spec : operatorv1.ClusterManagerSpec {
438+ RegistrationImagePullSpec : "quay.io/test/registration:latest" ,
439+ WorkImagePullSpec : "quay.io/test/work:latest" ,
440+ PlacementImagePullSpec : "quay.io/test/placement:latest" ,
441+ AddOnManagerImagePullSpec : "quay.io/test/addon-manager:latest" ,
442+ NodePlacement : operatorv1.NodePlacement {
443+ NodeSelector : map [string ]string {
444+ "node-role.kubernetes.io/infra" : "" ,
445+ },
446+ Tolerations : []v1.Toleration {
447+ {
448+ Key : "node-role.kubernetes.io/infra" ,
449+ Operator : v1 .TolerationOpExists ,
450+ Effect : v1 .TaintEffectNoSchedule ,
451+ },
452+ },
453+ },
454+ DeployOption : operatorv1.ClusterManagerDeployOption {
455+ Mode : operatorv1 .InstallModeDefault ,
456+ },
457+ RegistrationConfiguration : & operatorv1.RegistrationHubConfiguration {
458+ AutoApproveUsers : []string {"system:admin" },
459+ FeatureGates : []operatorv1.FeatureGate {
460+ {
461+ Feature : "DefaultClusterSet" ,
462+ Mode : operatorv1 .FeatureGateModeTypeEnable ,
463+ },
464+ },
465+ },
466+ WorkConfiguration : & operatorv1.WorkConfiguration {
467+ WorkDriver : operatorv1 .WorkDriverTypeKube ,
468+ FeatureGates : []operatorv1.FeatureGate {
469+ {
470+ Feature : "ManifestWorkReplicaSet" ,
471+ Mode : operatorv1 .FeatureGateModeTypeEnable ,
472+ },
473+ },
474+ },
475+ },
476+ }
477+
478+ createdClusterManager , err := operatorClient .OperatorV1 ().ClusterManagers ().Create (context .TODO (), clusterManager , metav1.CreateOptions {})
479+ Expect (err ).ToNot (HaveOccurred ())
480+ Expect (createdClusterManager .Spec .NodePlacement .NodeSelector ["node-role.kubernetes.io/infra" ]).Should (Equal ("" ))
481+ Expect (len (createdClusterManager .Spec .NodePlacement .Tolerations )).Should (Equal (1 ))
482+ Expect (createdClusterManager .Spec .RegistrationConfiguration .FeatureGates [0 ].Mode ).Should (Equal (operatorv1 .FeatureGateModeTypeEnable ))
483+ Expect (createdClusterManager .Spec .WorkConfiguration .FeatureGates [0 ].Mode ).Should (Equal (operatorv1 .FeatureGateModeTypeEnable ))
484+ })
485+
486+ It ("should validate addon manager configuration" , func () {
487+ clusterManager := & operatorv1.ClusterManager {
488+ ObjectMeta : metav1.ObjectMeta {
489+ Name : clusterManagerName ,
490+ },
491+ Spec : operatorv1.ClusterManagerSpec {
492+ AddOnManagerConfiguration : & operatorv1.AddOnManagerConfiguration {
493+ FeatureGates : []operatorv1.FeatureGate {
494+ {
495+ Feature : "AddonManagement" ,
496+ Mode : operatorv1 .FeatureGateModeTypeEnable ,
497+ },
498+ },
499+ },
500+ },
501+ }
502+
503+ createdClusterManager , err := operatorClient .OperatorV1 ().ClusterManagers ().Create (context .TODO (), clusterManager , metav1.CreateOptions {})
504+ Expect (err ).ToNot (HaveOccurred ())
505+ Expect (createdClusterManager .Spec .AddOnManagerConfiguration .FeatureGates [0 ].Feature ).Should (Equal ("AddonManagement" ))
506+ })
507+
508+ It ("should validate server configuration" , func () {
509+ clusterManager := & operatorv1.ClusterManager {
510+ ObjectMeta : metav1.ObjectMeta {
511+ Name : clusterManagerName ,
512+ },
513+ Spec : operatorv1.ClusterManagerSpec {
514+ ServerConfiguration : & operatorv1.ServerConfiguration {},
515+ },
516+ }
517+
518+ createdClusterManager , err := operatorClient .OperatorV1 ().ClusterManagers ().Create (context .TODO (), clusterManager , metav1.CreateOptions {})
519+ Expect (err ).ToNot (HaveOccurred ())
520+ Expect (createdClusterManager .Spec .ServerConfiguration ).ShouldNot (BeNil ())
521+ })
522+ })
523+
524+ Context ("ClusterManager resource requirements" , func () {
525+ It ("should handle resource requirements configuration" , func () {
526+ clusterManager := & operatorv1.ClusterManager {
527+ ObjectMeta : metav1.ObjectMeta {
528+ Name : clusterManagerName ,
529+ },
530+ Spec : operatorv1.ClusterManagerSpec {
531+ ResourceRequirement : & operatorv1.ResourceRequirement {
532+ Type : operatorv1 .ResourceQosClassResourceRequirement ,
533+ },
534+ },
535+ }
536+
537+ createdClusterManager , err := operatorClient .OperatorV1 ().ClusterManagers ().Create (context .TODO (), clusterManager , metav1.CreateOptions {})
538+ Expect (err ).ToNot (HaveOccurred ())
539+ Expect (createdClusterManager .Spec .ResourceRequirement .Type ).Should (Equal (operatorv1 .ResourceQosClassResourceRequirement ))
540+ })
541+ })
542+
543+ Context ("ClusterManager status updates" , func () {
544+ It ("should allow status updates" , func () {
545+ clusterManager := & operatorv1.ClusterManager {
546+ ObjectMeta : metav1.ObjectMeta {
547+ Name : clusterManagerName ,
548+ },
549+ Spec : operatorv1.ClusterManagerSpec {},
550+ }
551+
552+ createdClusterManager , err := operatorClient .OperatorV1 ().ClusterManagers ().Create (context .TODO (), clusterManager , metav1.CreateOptions {})
553+ Expect (err ).ToNot (HaveOccurred ())
554+
555+ // Update status
556+ createdClusterManager .Status = operatorv1.ClusterManagerStatus {
557+ ObservedGeneration : 1 ,
558+ Conditions : []metav1.Condition {
559+ {
560+ Type : "Applied" ,
561+ Status : metav1 .ConditionTrue ,
562+ Reason : "ClusterManagerDeployed" ,
563+ LastTransitionTime : metav1 .Now (),
564+ },
565+ },
566+ Generations : []operatorv1.GenerationStatus {
567+ {
568+ Group : "apps" ,
569+ Version : "v1" ,
570+ Resource : "deployments" ,
571+ Namespace : "open-cluster-management-hub" ,
572+ Name : "cluster-manager-registration-controller" ,
573+ LastGeneration : 1 ,
574+ },
575+ },
576+ RelatedResources : []operatorv1.RelatedResourceMeta {
577+ {
578+ Group : "apps" ,
579+ Version : "v1" ,
580+ Resource : "deployments" ,
581+ Namespace : "open-cluster-management-hub" ,
582+ Name : "cluster-manager-registration-controller" ,
583+ },
584+ },
585+ }
586+
587+ _ , err = operatorClient .OperatorV1 ().ClusterManagers ().UpdateStatus (context .TODO (), createdClusterManager , metav1.UpdateOptions {})
588+ Expect (err ).ToNot (HaveOccurred ())
589+ })
590+ })
591+ })
0 commit comments