Skip to content

Commit

Permalink
feature: add vpc crd
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Nov 4, 2020
1 parent b5ecac9 commit 921190e
Show file tree
Hide file tree
Showing 25 changed files with 1,320 additions and 293 deletions.
87 changes: 87 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,85 @@ echo "Install OVN DB in $addresses"
cat <<EOF > kube-ovn-crd.yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: vpcs.kubeovn.io
spec:
group: kubeovn.io
versions:
- additionalPrinterColumns:
- jsonPath: .status.standby
name: Standby
type: boolean
- jsonPath: .status.subnets
name: Subnets
type: string
name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
namespaces:
items:
type: string
type: array
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
type: string
lastUpdateTime:
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
type: object
type: array
default:
type: boolean
defaultLogicalSwitch:
type: string
router:
type: string
standby:
type: boolean
subnets:
items:
type: string
type: array
tcpLoadBalancer:
type: string
tcpSessionLoadBalancer:
type: string
udpLoadBalancer:
type: string
udpSessionLoadBalancer:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
names:
kind: Vpc
listKind: VpcList
plural: vpcs
shortNames:
- vpc
singular: vpc
scope: Cluster
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: ips.kubeovn.io
spec:
Expand Down Expand Up @@ -184,6 +263,9 @@ spec:
subresources:
status: {}
additionalPrinterColumns:
- name: Vpc
type: string
jsonPath: .spec.vpc
- name: Protocol
type: string
jsonPath: .spec.protocol
Expand Down Expand Up @@ -241,6 +323,8 @@ spec:
spec:
type: object
properties:
vpc:
type: string
default:
type: boolean
protocol:
Expand Down Expand Up @@ -888,6 +972,8 @@ rules:
- apiGroups:
- "kubeovn.io"
resources:
- vpcs
- vpcs/status
- subnets
- subnets/status
- ips
Expand Down Expand Up @@ -1862,6 +1948,7 @@ vsctl(){
}
diagnose(){
kubectl get crd vpcs.kubeovn.io
kubectl get crd subnets.kubeovn.io
kubectl get crd ips.kubeovn.io
kubectl get svc kube-dns -n kube-system
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kubeovn/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&SubnetList{},
&Vlan{},
&VlanList{},
&Vpc{},
&VpcList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/kubeovn/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ func (vs *VlanStatus) Bytes() ([]byte, error) {
klog.V(5).Info("status body", newStr)
return []byte(newStr), nil
}

func (vs *VpcStatus) Bytes() ([]byte, error) {
bytes, err := json.Marshal(vs)
if err != nil {
return nil, err
}
newStr := fmt.Sprintf(`{"status": %s}`, string(bytes))
klog.V(5).Info("status body", newStr)
return []byte(newStr), nil
}
65 changes: 65 additions & 0 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Subnet struct {

type SubnetSpec struct {
Default bool `json:"default"`
Vpc string `json:"vpc,omitempty"`
Protocol string `json:"protocol"`
Namespaces []string `json:"namespaces,omitempty"`
CIDRBlock string `json:"cidrBlock"`
Expand Down Expand Up @@ -195,3 +196,67 @@ type VlanList struct {

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

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

type Vpc struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VpcSpec `json:"spec"`
Status VpcStatus `json:"status,omitempty"`
}

type VpcSpec struct {
Namespaces []string `json:"namespaces,omitempty"`
}

type VpcStatus struct {
// Conditions represents the latest state of the object
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []VpcCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

Standby bool `json:"standby"`
Default bool `json:"default"`
DefaultLogicalSwitch string `json:"defaultLogicalSwitch"`
Router string `json:"router"`
TcpLoadBalancer string `json:"tcpLoadBalancer"`
UdpLoadBalancer string `json:"udpLoadBalancer"`
TcpSessionLoadBalancer string `json:"tcpSessionLoadBalancer"`
UdpSessionLoadBalancer string `json:"udpSessionLoadBalancer"`
Subnets []string `json:"subnets"`
}

// Condition describes the state of an object at a certain point.
// +k8s:deepcopy-gen=true
type VpcCondition struct {
// Type of condition.
Type ConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
// Last time the condition was probed
// +optional
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

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

type VpcList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Vpc `json:"items"`
}
128 changes: 128 additions & 0 deletions pkg/apis/kubeovn/v1/zz_generated.deepcopy.go

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

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

Loading

0 comments on commit 921190e

Please sign in to comment.