istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/kube/mcs/register.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package mcs
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  	"k8s.io/apimachinery/pkg/runtime"
    20  	"k8s.io/apimachinery/pkg/runtime/schema"
    21  	mcs "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
    22  
    23  	"istio.io/istio/pilot/pkg/features"
    24  )
    25  
    26  var (
    27  	schemeBuilder = &runtime.SchemeBuilder{}
    28  
    29  	// AddToScheme is used to register MCS CRDs to a runtime.Scheme
    30  	AddToScheme = schemeBuilder.AddToScheme
    31  
    32  	// MCSSchemeGroupVersion is group version used to register Kubernetes Multi-Cluster Services (MCS) objects
    33  	MCSSchemeGroupVersion = schema.GroupVersion{Group: features.MCSAPIGroup, Version: features.MCSAPIVersion}
    34  
    35  	ServiceExportGVR = MCSSchemeGroupVersion.WithResource("serviceexports")
    36  	ServiceImportGVR = MCSSchemeGroupVersion.WithResource("serviceimports")
    37  )
    38  
    39  func init() {
    40  	schemeBuilder.Register(addKnownTypes)
    41  }
    42  
    43  func addKnownTypes(scheme *runtime.Scheme) error {
    44  	// Register Kubernetes Multi-Cluster Services (MCS) objects.
    45  	scheme.AddKnownTypes(MCSSchemeGroupVersion,
    46  		&mcs.ServiceExport{},
    47  		&mcs.ServiceExportList{},
    48  		&mcs.ServiceImport{},
    49  		&mcs.ServiceImportList{})
    50  	metav1.AddToGroupVersion(scheme, MCSSchemeGroupVersion)
    51  
    52  	return nil
    53  }