@@ -31,6 +31,7 @@ const (
3131 Namespace = "cockroach-ns"
3232 LabelSelector = "app=cockroachdb"
3333 OperatorLabelSelector = "app=cockroach-operator"
34+ DefaultClusterDomain = "cluster.local"
3435 testOperatorRegistry = "us-docker.pkg.dev/releases-prod/self-hosted"
3536 testOperatorRepo = "cockroachdb-operator"
3637 testInitContainerRepo = "init-container"
@@ -558,91 +559,93 @@ func VerifyInitCommandInOperatorLogs(t *testing.T, kubectlOptions *k8s.KubectlOp
558559 require .Contains (t , logs , expected , "operator logs did not contain expected init command" )
559560}
560561
561- func patchCrdbnodesCRDToV1beta1 (t * testing.T , kubectlOptions * k8s.KubectlOptions ) {
562- _ , _ = retry .DoWithRetryE (t , "wait-for-crdbnodes-crd" , 20 , 3 * time .Second , func () (string , error ) {
563- return k8s .RunKubectlAndGetOutputE (t , kubectlOptions ,
564- "get" , "crd" , "crdbnodes.crdb.cockroachlabs.com" , "-o" , "name" )
565- })
566-
567- // Check idempotency: skip if v1beta1 is already served.
568- served , _ := k8s .RunKubectlAndGetOutputE (t , kubectlOptions ,
569- "get" , "crd" , "crdbnodes.crdb.cockroachlabs.com" ,
570- "-o" , `jsonpath={.spec.versions[?(@.name=="v1beta1")].served}` )
571- if served == "true" {
572- t .Log ("crdbnodes CRD already has v1beta1 served, skipping patch" )
573- return
574- }
575-
576- crdbnodesJSON , err := k8s .RunKubectlAndGetOutputE (t , kubectlOptions ,
577- "get" , "crd" , "crdbnodes.crdb.cockroachlabs.com" , "-o" , "json" )
578- if err != nil {
579- t .Logf ("Warning: failed to get crdbnodes CRD for patching: %v" , err )
580- return
581- }
582-
583- var crdObj map [string ]interface {}
584- if jsonErr := json .Unmarshal ([]byte (crdbnodesJSON ), & crdObj ); jsonErr != nil {
585- t .Logf ("Warning: failed to parse crdbnodes CRD JSON: %v" , jsonErr )
586- return
587- }
588- spec , _ := crdObj ["spec" ].(map [string ]interface {})
589- versions , _ := spec ["versions" ].([]interface {})
590-
591- var v1alpha1Entry map [string ]interface {}
592- for _ , v := range versions {
593- vMap , ok := v .(map [string ]interface {})
594- if ! ok {
595- continue
596- }
597- if vMap ["name" ] == "v1alpha1" {
598- b , _ := json .Marshal (vMap )
599- json .Unmarshal (b , & v1alpha1Entry ) //nolint:errcheck
600- break
601- }
602- }
603- if v1alpha1Entry == nil {
604- t .Log ("Warning: crdbnodes CRD has no v1alpha1 entry to clone as v1beta1" )
605- return
606- }
607-
608- // Clone v1alpha1 schema into a new v1beta1 entry and mark v1alpha1 non-storage.
609- v1beta1Entry := make (map [string ]interface {})
610- b , _ := json .Marshal (v1alpha1Entry )
611- json .Unmarshal (b , & v1beta1Entry ) //nolint:errcheck
612- v1beta1Entry ["name" ] = "v1beta1"
613- v1beta1Entry ["storage" ] = true
614- v1beta1Entry ["served" ] = true
615- v1alpha1Entry ["storage" ] = false
616- v1alpha1Entry ["served" ] = false
617-
618- patch := map [string ]interface {}{
619- "spec" : map [string ]interface {}{
620- "versions" : []interface {}{v1alpha1Entry , v1beta1Entry },
621- },
622- }
623- patchBytes , marshalErr := json .Marshal (patch )
624- if marshalErr != nil {
625- t .Logf ("Warning: failed to marshal crdbnodes patch: %v" , marshalErr )
626- return
627- }
628-
629- patchFile , tmpErr := os .CreateTemp ("" , "crdbnodes-v1beta1-patch-*.json" )
630- if tmpErr != nil {
631- t .Logf ("Warning: failed to create temp file for crdbnodes patch: %v" , tmpErr )
632- return
633- }
634- defer os .Remove (patchFile .Name ())
635- patchFile .Write (patchBytes ) //nolint:errcheck
636- patchFile .Close ()
637-
638- if patchErr := k8s .RunKubectlE (t , kubectlOptions , "patch" , "crd" ,
639- "crdbnodes.crdb.cockroachlabs.com" , "--type=merge" ,
640- fmt .Sprintf ("--patch-file=%s" , patchFile .Name ())); patchErr != nil {
641- t .Logf ("Warning: failed to patch crdbnodes CRD: %v" , patchErr )
642- } else {
643- t .Log ("Patched crdbnodes CRD to add v1beta1 version" )
644- }
645- }
562+ // patchCrdbnodesCRDToV1beta1 is kept for reference in case an older operator image is used
563+ // that installs crdbnodes with only v1alpha1. With a v1beta1-native operator image this is not needed.
564+ // Uncomment and call from InstallCockroachDBEnterpriseOperator if reverting to an older image.
565+ //
566+ // func patchCrdbnodesCRDToV1beta1(t *testing.T, kubectlOptions *k8s.KubectlOptions) {
567+ // _, _ = retry.DoWithRetryE(t, "wait-for-crdbnodes-crd", 20, 3*time.Second, func() (string, error) {
568+ // return k8s.RunKubectlAndGetOutputE(t, kubectlOptions,
569+ // "get", "crd", "crdbnodes.crdb.cockroachlabs.com", "-o", "name")
570+ // })
571+ //
572+ // served, _ := k8s.RunKubectlAndGetOutputE(t, kubectlOptions,
573+ // "get", "crd", "crdbnodes.crdb.cockroachlabs.com",
574+ // "-o", `jsonpath={.spec.versions[?(@.name=="v1beta1")].served}`)
575+ // if served == "true" {
576+ // t.Log("crdbnodes CRD already has v1beta1 served, skipping patch")
577+ // return
578+ // }
579+ //
580+ // crdbnodesJSON, err := k8s.RunKubectlAndGetOutputE(t, kubectlOptions,
581+ // "get", "crd", "crdbnodes.crdb.cockroachlabs.com", "-o", "json")
582+ // if err != nil {
583+ // t.Logf("Warning: failed to get crdbnodes CRD for patching: %v", err)
584+ // return
585+ // }
586+ //
587+ // var crdObj map[string]interface{}
588+ // if jsonErr := json.Unmarshal([]byte(crdbnodesJSON), &crdObj); jsonErr != nil {
589+ // t.Logf("Warning: failed to parse crdbnodes CRD JSON: %v", jsonErr)
590+ // return
591+ // }
592+ // spec, _ := crdObj["spec"].(map[string]interface{})
593+ // versions, _ := spec["versions"].([]interface{})
594+ //
595+ // var v1alpha1Entry map[string]interface{}
596+ // for _, v := range versions {
597+ // vMap, ok := v.(map[string]interface{})
598+ // if !ok {
599+ // continue
600+ // }
601+ // if vMap["name"] == "v1alpha1" {
602+ // b, _ := json.Marshal(vMap)
603+ // json.Unmarshal(b, &v1alpha1Entry) //nolint:errcheck
604+ // break
605+ // }
606+ // }
607+ // if v1alpha1Entry == nil {
608+ // t.Log("Warning: crdbnodes CRD has no v1alpha1 entry to clone as v1beta1")
609+ // return
610+ // }
611+ //
612+ // v1beta1Entry := make(map[string]interface{})
613+ // b, _ := json.Marshal(v1alpha1Entry)
614+ // json.Unmarshal(b, &v1beta1Entry) //nolint:errcheck
615+ // v1beta1Entry["name"] = "v1beta1"
616+ // v1beta1Entry["storage"] = true
617+ // v1beta1Entry["served"] = true
618+ // v1alpha1Entry["storage"] = false
619+ // v1alpha1Entry["served"] = false
620+ //
621+ // patch := map[string]interface{}{
622+ // "spec": map[string]interface{}{
623+ // "versions": []interface{}{v1alpha1Entry, v1beta1Entry},
624+ // },
625+ // }
626+ // patchBytes, marshalErr := json.Marshal(patch)
627+ // if marshalErr != nil {
628+ // t.Logf("Warning: failed to marshal crdbnodes patch: %v", marshalErr)
629+ // return
630+ // }
631+ //
632+ // patchFile, tmpErr := os.CreateTemp("", "crdbnodes-v1beta1-patch-*.json")
633+ // if tmpErr != nil {
634+ // t.Logf("Warning: failed to create temp file for crdbnodes patch: %v", tmpErr)
635+ // return
636+ // }
637+ // defer os.Remove(patchFile.Name())
638+ // patchFile.Write(patchBytes) //nolint:errcheck
639+ // patchFile.Close()
640+ //
641+ // if patchErr := k8s.RunKubectlE(t, kubectlOptions, "patch", "crd",
642+ // "crdbnodes.crdb.cockroachlabs.com", "--type=merge",
643+ // fmt.Sprintf("--patch-file=%s", patchFile.Name())); patchErr != nil {
644+ // t.Logf("Warning: failed to patch crdbnodes CRD: %v", patchErr)
645+ // } else {
646+ // t.Log("Patched crdbnodes CRD to add v1beta1 version")
647+ // }
648+ // }
646649
647650func InstallCockroachDBEnterpriseOperator (t * testing.T , kubectlOptions * k8s.KubectlOptions , cloudRegion string ) {
648651 _ , operatorChartPath := HelmChartPaths ()
@@ -684,7 +687,7 @@ func InstallCockroachDBEnterpriseOperator(t *testing.T, kubectlOptions *k8s.Kube
684687 return out , nil
685688 })
686689
687- patchCrdbnodesCRDToV1beta1 (t , kubectlOptions )
690+ // patchCrdbnodesCRDToV1beta1(t, kubectlOptions) // not needed with v1beta1-native operator image
688691
689692 // wait for the operator pod to be running
690693 pods := k8s .ListPods (t , kubectlOptions , metav1.ListOptions {
0 commit comments