Skip to content

Commit e52e492

Browse files
authored
Merge pull request #6 from shaofan-hs/cluster-v1beta1
add cluster/v1beta1
2 parents f2276ab + a731a3d commit e52e492

File tree

8 files changed

+465
-10
lines changed

8 files changed

+465
-10
lines changed

.licenserc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ header:
6161
- '**/Dockerfile'
6262
- '**/.dockerignore'
6363
comment: never
64-
license-location-threshold: 80
64+
license-location-threshold: 100

cluster/v1beta1/doc.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright The Karbour 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+
// +k8s:openapi-gen=true
18+
// +k8s:deepcopy-gen=package
19+
// +k8s:conversion-gen=github.com/KusionStack/karbour/pkg/kubernetes/apis/cluster
20+
// +k8s:defaulter-gen=TypeMeta
21+
// +groupName=cluster.karbour.com
22+
23+
// Package v1beta1 Package v1beta1 is the v1beta1 version of the API.
24+
package v1beta1 // import "github.com/KusionStack/karbour/pkg/kubernetes/apis/cluster/v1beta1"

cluster/v1beta1/register.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright The Karbour 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 v1beta1
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+
)
24+
25+
// GroupName holds the API group name.
26+
const GroupName = "cluster.karbour.com"
27+
28+
// SchemeGroupVersion is group version used to register these objects
29+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"}
30+
31+
var (
32+
// SchemeBuilder allows to add this group to a scheme.
33+
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
34+
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
35+
SchemeBuilder runtime.SchemeBuilder
36+
localSchemeBuilder = &SchemeBuilder
37+
38+
// AddToScheme adds this group to a scheme.
39+
AddToScheme = localSchemeBuilder.AddToScheme
40+
)
41+
42+
func init() {
43+
// We only register manually written functions here. The registration of the
44+
// generated functions takes place in the generated files. The separation
45+
// makes the code compile even when the generated files are missing.
46+
localSchemeBuilder.Register(addKnownTypes)
47+
}
48+
49+
// Adds the list of known types to the given scheme.
50+
func addKnownTypes(scheme *runtime.Scheme) error {
51+
scheme.AddKnownTypes(SchemeGroupVersion,
52+
&Cluster{},
53+
&ClusterList{},
54+
&ClusterProxyOptions{},
55+
)
56+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
57+
return nil
58+
}
59+
60+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
61+
func Resource(resource string) schema.GroupResource {
62+
return SchemeGroupVersion.WithResource(resource).GroupResource()
63+
}

cluster/v1beta1/types.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright The Karbour 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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
type CredentialType string
24+
25+
const (
26+
CredentialTypeServiceAccountToken CredentialType = "ServiceAccountToken"
27+
CredentialTypeX509Certificate CredentialType = "X509Certificate"
28+
)
29+
30+
// +genclient
31+
// +genclient:nonNamespaced
32+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
33+
34+
// Cluster is an extension type to access a cluster
35+
type Cluster struct {
36+
metav1.TypeMeta `json:",inline"`
37+
metav1.ObjectMeta `json:"metadata,omitempty"` //nolint:tagliatelle
38+
39+
Spec ClusterSpec `json:"spec"`
40+
// +optional
41+
Status ClusterStatus `json:"status,omitempty"`
42+
}
43+
44+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
45+
46+
// ClusterList is a list of Cluster objects.
47+
type ClusterList struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ListMeta `json:"metadata,omitempty"` //nolint:tagliatelle
50+
51+
Items []Cluster `json:"items"`
52+
}
53+
54+
type ClusterSpec struct {
55+
Provider string `json:"provider"`
56+
Access ClusterAccess `json:"access"`
57+
// +optional
58+
Description string `json:"description"`
59+
DisplayName string `json:"displayName"`
60+
Finalized *bool `json:"finalized,omitempty"`
61+
}
62+
63+
type ClusterStatus struct {
64+
// +optional
65+
Healthy bool `json:"healthy,omitempty"`
66+
}
67+
68+
type ClusterAccess struct {
69+
Endpoint string `json:"endpoint"`
70+
// +optional
71+
CABundle []byte `json:"caBundle,omitempty"`
72+
// +optional
73+
Insecure *bool `json:"insecure,omitempty"`
74+
// +optional
75+
Credential *ClusterAccessCredential `json:"credential,omitempty"`
76+
}
77+
78+
type ClusterAccessCredential struct {
79+
Type CredentialType `json:"type"`
80+
// +optional
81+
ServiceAccountToken string `json:"serviceAccountToken,omitempty"`
82+
// +optional
83+
X509 *X509 `json:"x509,omitempty"`
84+
}
85+
86+
type X509 struct {
87+
Certificate []byte `json:"certificate"`
88+
PrivateKey []byte `json:"privateKey"`
89+
}
90+
91+
// +k8s:conversion-gen:explicit-from=net/url.Values
92+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
93+
94+
type ClusterProxyOptions struct {
95+
metav1.TypeMeta `json:",inline"`
96+
97+
// Path is the target api path of the proxy request.
98+
// e.g. "/healthz", "/api/v1"
99+
// +optional
100+
Path string `json:"path,omitempty"`
101+
}

0 commit comments

Comments
 (0)