github.com/GoogleContainerTools/kpt/porch/api@v0.0.0-20240427025202-5cbd3cbd9237/porchconfig/v1alpha1/groupversion_info.go (about)

     1  // Copyright 2022 The kpt 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 v1alpha1 contains API Schema definitions for the v1alpha1 API group
    16  // +kubebuilder:object:generate=true
    17  // +groupName=config.porch.kpt.dev
    18  package v1alpha1
    19  
    20  import (
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	"k8s.io/apimachinery/pkg/runtime/schema"
    24  )
    25  
    26  //go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 object:headerFile="../../../scripts/boilerplate.go.txt" crd:crdVersions=v1 output:crd:artifacts:config=. paths=./...
    27  
    28  var (
    29  	// GroupVersion is group version used to register these objects
    30  	GroupVersion = schema.GroupVersion{Group: "config.porch.kpt.dev", Version: "v1alpha1"}
    31  
    32  	// We removed SchemeBuilder to keep our dependencies small
    33  
    34  	TypeRepository = TypeInfo{
    35  		Kind:     "Repository",
    36  		Resource: GroupVersion.WithResource("repositories"),
    37  		objects:  []runtime.Object{&Repository{}, &RepositoryList{}},
    38  	}
    39  
    40  	TypeFunction = TypeInfo{
    41  		Kind:     "Function",
    42  		Resource: GroupVersion.WithResource("functions"),
    43  		objects:  []runtime.Object{&Function{}, &FunctionList{}},
    44  	}
    45  
    46  	AllKinds = []TypeInfo{TypeRepository, TypeFunction}
    47  )
    48  
    49  //+kubebuilder:object:generate=false
    50  
    51  // TypeInfo holds type meta-information
    52  type TypeInfo struct {
    53  	Kind     string
    54  	Resource schema.GroupVersionResource
    55  	objects  []runtime.Object
    56  }
    57  
    58  // GVK returns the schema.GroupVersionKind for the type
    59  func (t *TypeInfo) GVK() schema.GroupVersionKind {
    60  	return t.Resource.GroupVersion().WithKind(t.Kind)
    61  }
    62  
    63  // APIVersion returns the apiVersion for the type
    64  func (t *TypeInfo) APIVersion() string {
    65  	return t.Resource.GroupVersion().Identifier()
    66  }
    67  
    68  // GroupResource returns the GroupResource for the kind
    69  func (t *TypeInfo) GroupResource() schema.GroupResource {
    70  	return t.Resource.GroupResource()
    71  }
    72  
    73  func AddToScheme(scheme *runtime.Scheme) error {
    74  	for _, kind := range AllKinds {
    75  		scheme.AddKnownTypes(GroupVersion, kind.objects...)
    76  	}
    77  	metav1.AddToGroupVersion(scheme, GroupVersion)
    78  	return nil
    79  }