github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/apis/core/v1alpha1/register.go (about) 1 /* 2 Copyright 2020 The Tilt Dev Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/runtime" 22 "k8s.io/apimachinery/pkg/runtime/schema" 23 utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 25 "github.com/tilt-dev/tilt-apiserver/pkg/server/builder/resource" 26 ) 27 28 // GroupName is the group name used in this package 29 const GroupName = "tilt.dev" 30 31 const Version = "v1alpha1" 32 33 // AnnotationTargetID is an internal Tilt target ID used for the build graph. 34 const AnnotationTargetID = "tilt.dev/target-id" 35 36 // AnnotationManaged declares when an object is managed by a system 37 // that's not entirely expressed in apiserver objects. 38 const AnnotationManagedBy = "tilt.dev/managed-by" 39 40 // AnnotationManifest identifies which manifest an object's logs should appear under. 41 const AnnotationManifest = "tilt.dev/resource" 42 43 // An annotation on any object that identifies which span id 44 // its logs should appear under. 45 const AnnotationSpanID = "tilt.dev/log-span-id" 46 47 // Denote that the Tiltfile is the owner. 48 const OwnerKindTiltfile = "Tiltfile" 49 50 // SchemeGroupVersion is group version used to register these objects 51 var localSchemeBuilder = runtime.NewSchemeBuilder(AddToScheme) 52 var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: Version} 53 54 func AllResourceObjects() []resource.Object { 55 return []resource.Object{ 56 &Session{}, 57 &FileWatch{}, 58 &Cmd{}, 59 &KubernetesApply{}, 60 &KubernetesDiscovery{}, 61 &PodLogStream{}, 62 &UISession{}, 63 &UIResource{}, 64 &UIButton{}, 65 &PortForward{}, 66 &ImageMap{}, 67 &Tiltfile{}, 68 &ConfigMap{}, 69 &Extension{}, 70 &ExtensionRepo{}, 71 &LiveUpdate{}, 72 &ToggleButton{}, 73 &DockerImage{}, 74 &CmdImage{}, 75 &Cluster{}, 76 &DockerComposeService{}, 77 &DockerComposeLogStream{}, 78 79 // Hey! You! If you're adding a new top-level type, add the type object here. 80 } 81 } 82 func AllResourceLists() []runtime.Object { 83 return []runtime.Object{ 84 &SessionList{}, 85 &FileWatchList{}, 86 &CmdList{}, 87 &KubernetesApplyList{}, 88 &KubernetesDiscoveryList{}, 89 &PodLogStreamList{}, 90 &UISessionList{}, 91 &UIResourceList{}, 92 &UIButtonList{}, 93 &PortForwardList{}, 94 &ImageMapList{}, 95 &TiltfileList{}, 96 &ConfigMapList{}, 97 &ExtensionList{}, 98 &ExtensionRepoList{}, 99 &LiveUpdateList{}, 100 &ToggleButtonList{}, 101 &DockerImageList{}, 102 &CmdImageList{}, 103 &ClusterList{}, 104 &DockerComposeServiceList{}, 105 &DockerComposeLogStreamList{}, 106 107 // Hey! You! If you're adding a new top-level type, add the List type here. 108 } 109 } 110 111 var AddToScheme = func(scheme *runtime.Scheme) error { 112 metav1.AddToGroupVersion(scheme, schema.GroupVersion{ 113 Group: GroupName, 114 Version: Version, 115 }) 116 117 objs := []runtime.Object{} 118 for _, obj := range AllResourceObjects() { 119 objs = append(objs, obj) 120 } 121 objs = append(objs, AllResourceLists()...) 122 123 scheme.AddKnownTypes(schema.GroupVersion{ 124 Group: GroupName, 125 Version: Version, 126 }, objs...) 127 return nil 128 } 129 130 // Resource takes an unqualified resource and returns a Group qualified GroupResource 131 func Resource(resource string) schema.GroupResource { 132 return SchemeGroupVersion.WithResource(resource).GroupResource() 133 } 134 135 // A new scheme with just this package's types. 136 func NewScheme() *runtime.Scheme { 137 scheme := runtime.NewScheme() 138 utilruntime.Must(AddToScheme(scheme)) 139 return scheme 140 }