Skip to content

Commit

Permalink
Add CRD Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Jun 19, 2020
1 parent 178b33b commit 8e7de75
Show file tree
Hide file tree
Showing 21 changed files with 1,368 additions and 90 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ resources:
- group: onecloud
kind: AnsiblePlaybook
version: v1
- group: onecloud
kind: Endpoint
version: v1
version: "2"
24 changes: 24 additions & 0 deletions api/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ func (apStatus *AnsiblePlaybookStatus) SetBaseExternalInfo(info ExternalInfoBase
apStatus.ExternalInfo.ExternalInfoBase = info
}

func (epStatus *EndpointStatus) GetBaseExternalInfo() ExternalInfoBase {
return epStatus.ExternalInfo
}

func (epStatus *EndpointStatus) DeepCopy2() IResourceStatus {
return epStatus.DeepCopy()
}

func (epStatus *EndpointStatus) SetBaseExternalInfo(info ExternalInfoBase) {
epStatus.ExternalInfo = info
}

func (vm *VirtualMachine) GetResourceStatus() IResourceStatus {
return &vm.Status
}
Expand All @@ -196,3 +208,15 @@ func (ap *AnsiblePlaybook) SetResourceStatus(is IResourceStatus) {
func (ap *AnsiblePlaybook) GetResourceSpec() IResourceSpec {
return &ap.Spec
}

func (ep *Endpoint) GetResourceStatus() IResourceStatus {
return &ep.Status
}

func (ep *Endpoint) SetResourceStatus(is IResourceStatus) {
ep.Status = *is.(*EndpointStatus)
}

func (ep *Endpoint) GetResourceSpec() IResourceSpec {
return &ep.Spec
}
86 changes: 86 additions & 0 deletions api/v1/endpoint_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2020 Yunion
//
// 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 v1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// EndpointSpec defines the desired state of Endpoint
type EndpointSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Url of this Endpoint
URL URL `json:"url"`
RegionId string `json:"regionId"`
// +optional
Name string `json:"name,omitempty"`
// +optional
Disabled *bool `json:"disabled,omitempty"`
// Service certificate id or name
// +optional
ServiceCertificate string `json:"serviceCertificate,omitempty"`
ResourceSpecBase `json:",inline"`
}

// URL is used to construct url string 'Protocol://Host:Port/Prefix'
type URL struct {
// +optional
Protocol string `json:"protocol,omitempty"`
Host StringStore `json:"host,omitempty"`
// +optional
Port *int32 `json:"port,omitempty"`
// +optional
Prefix string `json:"prefix,omitempty"`
}

// EndpointStatus defines the observed state of Endpoint
type EndpointStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

ResourceStatusBase `json:",inline"`
// +optional
ExternalInfo ExternalInfoBase `json:"externalInfo,omitempty"`
}

// +kubebuilder:object:root=true

// Endpoint is the Schema for the endpoints API
// +kubebuilder:subresource:status
type Endpoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EndpointSpec `json:"spec,omitempty"`
Status EndpointStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// EndpointList contains a list of Endpoint
type EndpointList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Endpoint `json:"items"`
}

func init() {
SchemeBuilder.Register(&Endpoint{}, &EndpointList{})
}
119 changes: 119 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

133 changes: 133 additions & 0 deletions config/crd/bases/onecloud.yunion.io_endpoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: endpoints.onecloud.yunion.io
spec:
group: onecloud.yunion.io
names:
kind: Endpoint
listKind: EndpointList
plural: endpoints
singular: endpoint
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: Endpoint is the Schema for the endpoints API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: EndpointSpec defines the desired state of Endpoint
properties:
disabled:
type: boolean
maxRetryTimes:
description: Nil or Non-positive number means unlimited.
format: int32
type: integer
name:
type: string
regionId:
type: string
serviceCertificate:
description: Service certificate id or name
type: string
url:
description: Url of this Endpoint
properties:
host:
properties:
reference:
properties:
fieldPath:
type: string
group:
type: string
kind:
type: string
name:
type: string
namespace:
type: string
version:
type: string
required:
- fieldPath
- kind
- name
- namespace
type: object
value:
type: string
type: object
port:
format: int32
type: integer
prefix:
type: string
protocol:
type: string
type: object
required:
- regionId
- url
type: object
status:
description: EndpointStatus defines the observed state of Endpoint
properties:
externalInfo:
description: ExternalInfoBase describe the corresponding resource's
info in external system
properties:
action:
description: Action indicate the latest action for external vm.
type: string
id:
type: string
status:
type: string
type: object
phase:
description: ResourcePhase is a label for the condition of a resource
at the current time
type: string
reason:
description: A human readable message indicating details about why resource
is in this phase.
type: string
tryTimes:
description: TryTimes record the continuous try times.
format: int32
type: integer
required:
- tryTimes
type: object
type: object
version: v1
versions:
- name: v1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

0 comments on commit 8e7de75

Please sign in to comment.