-
Notifications
You must be signed in to change notification settings - Fork 292
/
cluster_types.go
183 lines (146 loc) · 5.52 KB
/
cluster_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright 2021 The Tilt Dev Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"github.com/tilt-dev/tilt-apiserver/pkg/server/builder/resource"
"github.com/tilt-dev/tilt-apiserver/pkg/server/builder/resource/resourcestrategy"
)
const ClusterNameDefault = "default"
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Cluster defines any runtime for running containers, in the broadest
// sense of the word "runtime".
//
// +k8s:openapi-gen=true
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec ClusterSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status ClusterStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// ClusterList
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []Cluster `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// ClusterSpec defines how to find the cluster we're running
// containers on.
//
// Tilt currently supports connecting to an existing Kubernetes
// cluster or an existing Docker Daemon (for Docker Compose).
type ClusterSpec struct {
// Connection spec for an existing cluster.
Connection *ClusterConnection `json:"connection,omitempty" protobuf:"bytes,1,opt,name=connection"`
}
// Connection spec for an existing cluster.
type ClusterConnection struct {
// Defines connection to a Kubernetes cluster.
Kubernetes *KubernetesClusterConnection `json:"kubernetes,omitempty" protobuf:"bytes,1,opt,name=kubernetes"`
// Defines connection to a Docker daemon.
Docker *DockerClusterConnection `json:"docker,omitempty" protobuf:"bytes,2,opt,name=docker"`
}
type KubernetesClusterConnection struct {
// The name of the kubeconfig context to use.
//
// If not specified, will use the default context in the kubeconfig.
Context string `json:"context,omitempty" protobuf:"bytes,1,opt,name=context"`
// The default namespace to use.
//
// If not specified, will use the namespace in the kubeconfig.
Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
}
type DockerClusterConnection struct {
// The docker host to use.
//
// If not specified, will read the DOCKER_HOST env or use the default docker
// host.
Host string `json:"host,omitempty" protobuf:"bytes,1,opt,name=host"`
}
var _ resource.Object = &Cluster{}
var _ resourcestrategy.Validater = &Cluster{}
func (in *Cluster) GetSpec() interface{} {
return in.Spec
}
func (in *Cluster) GetObjectMeta() *metav1.ObjectMeta {
return &in.ObjectMeta
}
func (in *Cluster) NamespaceScoped() bool {
return false
}
func (in *Cluster) New() runtime.Object {
return &Cluster{}
}
func (in *Cluster) NewList() runtime.Object {
return &ClusterList{}
}
func (in *Cluster) GetGroupVersionResource() schema.GroupVersionResource {
return schema.GroupVersionResource{
Group: "tilt.dev",
Version: "v1alpha1",
Resource: "clusters",
}
}
func (in *Cluster) IsStorageVersion() bool {
return true
}
func (in *Cluster) Validate(ctx context.Context) field.ErrorList {
// TODO(user): Modify it, adding your API validation here.
return nil
}
var _ resource.ObjectList = &ClusterList{}
func (in *ClusterList) GetListMeta() *metav1.ListMeta {
return &in.ListMeta
}
// ClusterStatus defines the observed state of Cluster
type ClusterStatus struct {
// The preferred chip architecture of the cluster.
//
// On Kubernetes, this will correspond to the kubernetes.io/arch annotation on
// a node.
//
// On Docker, this will be the Architecture of the Docker daemon.
//
// Note that many clusters support multiple chipsets. This field doesn't intend
// that this is the only architecture a cluster supports, only that it's one
// of the architectures.
Arch string `json:"arch,omitempty" protobuf:"bytes,1,opt,name=arch"`
// An unrecoverable error connecting to the cluster.
//
// +optional
Error string `json:"error,omitempty" protobuf:"bytes,2,opt,name=error"`
// ConnectedAt indicates the time at which the cluster connection was established.
//
// Consumers can use this to detect when the underlying config has changed
// and refresh their client/connection accordingly.
//
// +optional
ConnectedAt *metav1.MicroTime `json:"connectedAt,omitempty" protobuf:"bytes,3,opt,name=connectedAt"`
}
// Cluster implements ObjectWithStatusSubResource interface.
var _ resource.ObjectWithStatusSubResource = &Cluster{}
func (in *Cluster) GetStatus() resource.StatusSubResource {
return in.Status
}
// ClusterStatus{} implements StatusSubResource interface.
var _ resource.StatusSubResource = &ClusterStatus{}
func (in ClusterStatus) CopyTo(parent resource.ObjectWithStatusSubResource) {
parent.(*Cluster).Status = in
}