...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gvks/gvks.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gvks

     1  // Copyright 2022 Google LLC
     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  package gvks
    15  
    16  import (
    17  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/metadata"
    18  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gvks/externalonlygvks"
    19  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gvks/supportedgvks"
    20  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/servicemapping/servicemappingloader"
    21  	"k8s.io/apimachinery/pkg/runtime/schema"
    22  )
    23  
    24  // All returns GroupVersionKinds corresponding to GCP resources known to KCC,
    25  // including those unsupported by KCC but commonly referenced by KCC resources.
    26  func All(smLoader *servicemappingloader.ServiceMappingLoader, serviceMetaLoader metadata.ServiceMetadataLoader) []schema.GroupVersionKind {
    27  	gvks := supportedgvks.All(smLoader, serviceMetaLoader)
    28  	gvks = append(gvks, externalonlygvks.All()...)
    29  	return gvks
    30  }
    31  
    32  func GVKForKind(kind string, smLoader *servicemappingloader.ServiceMappingLoader,
    33  	serviceMetaLoader metadata.ServiceMetadataLoader) (gvk schema.GroupVersionKind, found bool) {
    34  	for _, v := range All(smLoader, serviceMetaLoader) {
    35  		if v.Kind == kind {
    36  			return v, true
    37  		}
    38  	}
    39  	return schema.GroupVersionKind{}, false
    40  }
    41  

View as plain text