Skip to content

Commit

Permalink
add cluster/v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
shaofan-hs committed Mar 12, 2024
1 parent f2276ab commit 7285c1a
Show file tree
Hide file tree
Showing 9 changed files with 806 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ header:
- '**/Dockerfile'
- '**/.dockerignore'
comment: never
license-location-threshold: 80
license-location-threshold: 100
24 changes: 24 additions & 0 deletions cluster/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright The Karbour 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.
*/

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=github.com/KusionStack/karbour/pkg/kubernetes/apis/cluster
// +k8s:defaulter-gen=TypeMeta
// +groupName=cluster.karbour.com

// Package v1beta1 Package v1beta1 is the v1beta1 version of the API.
package v1beta1 // import "github.com/KusionStack/karbour/pkg/kubernetes/apis/cluster/v1beta1"
63 changes: 63 additions & 0 deletions cluster/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright The Karbour 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName holds the API group name.
const GroupName = "cluster.karbour.com"

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"}

var (
// SchemeBuilder allows to add this group to a scheme.
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder

// AddToScheme adds this group to a scheme.
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Cluster{},
&ClusterList{},
&ClusterProxyOptions{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
101 changes: 101 additions & 0 deletions cluster/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright The Karbour 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type CredentialType string

const (
CredentialTypeServiceAccountToken CredentialType = "ServiceAccountToken"
CredentialTypeX509Certificate CredentialType = "X509Certificate"
)

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Cluster is an extension type to access a cluster
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"` //nolint:tagliatelle

Spec ClusterSpec `json:"spec"`
// +optional
Status ClusterStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterList is a list of Cluster objects.
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"` //nolint:tagliatelle

Items []Cluster `json:"items"`
}

type ClusterSpec struct {
Provider string `json:"provider"`
Access ClusterAccess `json:"access"`
// +optional
Description string `json:"description"`
DisplayName string `json:"displayName"`
Finalized *bool `json:"finalized,omitempty"`
}

type ClusterStatus struct {
// +optional
Healthy bool `json:"healthy,omitempty"`
}

type ClusterAccess struct {
Endpoint string `json:"endpoint"`
// +optional
CABundle []byte `json:"caBundle,omitempty"`
// +optional
Insecure *bool `json:"insecure,omitempty"`
// +optional
Credential *ClusterAccessCredential `json:"credential,omitempty"`
}

type ClusterAccessCredential struct {
Type CredentialType `json:"type"`
// +optional
ServiceAccountToken string `json:"serviceAccountToken,omitempty"`
// +optional
X509 *X509 `json:"x509,omitempty"`
}

type X509 struct {
Certificate []byte `json:"certificate"`
PrivateKey []byte `json:"privateKey"`
}

// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type ClusterProxyOptions struct {
metav1.TypeMeta `json:",inline"`

// Path is the target api path of the proxy request.
// e.g. "/healthz", "/api/v1"
// +optional
Path string `json:"path,omitempty"`
}
Loading

0 comments on commit 7285c1a

Please sign in to comment.