Skip to content

Commit

Permalink
Add code generator
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Dec 22, 2017
1 parent 11f6196 commit 68f187f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 188 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ install:
- go get -u github.com/rmohr/mock/mockgen
- go get -u github.com/rmohr/go-swagger-utils/swagger-doc
- go get -u github.com/onsi/ginkgo/ginkgo
- go get -u k8s.io/code-generator/cmd/deepcopy-gen
- go get -u k8s.io/code-generator/cmd/defaulter-gen
- sudo apt-get install libvirt-dev make
- make sync

Expand Down
2 changes: 2 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ go get -u github.com/golang/mock/gomock
go get -u github.com/rmohr/mock/mockgen
go get -u github.com/rmohr/go-swagger-utils/swagger-doc
go get github.com/onsi/ginkgo/ginkgo
go get -u k8s.io/code-generator/cmd/deepcopy-gen
go get -u k8s.io/code-generator/cmd/defaulter-gen
```

Then regenerate the code:
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/v1/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v1

func SetDefaults_VirtualMachine(obj *VirtualMachine) {

}
4 changes: 4 additions & 0 deletions pkg/api/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// +k8s:deepcopy-gen=package
// +k8s:defaulter-gen=TypeMeta

package v1
194 changes: 6 additions & 188 deletions pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ package v1
import (
"encoding/json"
"fmt"
"reflect"

"github.com/jeevatkm/go-model"
"github.com/satori/go.uuid"

k8sv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -73,7 +69,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VirtualMachineList{},
&metav1.ListOptions{},
&metav1.DeleteOptions{},
&Spice{},
&Migration{},
&MigrationList{},
&VirtualMachineReplicaSet{},
Expand All @@ -96,17 +91,10 @@ func init() {
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme.Scheme); err != nil {
panic(err)
}

// TODO the whole mapping registration can be done be an automatic process with reflection
model.AddConversion((*uuid.UUID)(nil), (*string)(nil), func(in reflect.Value) (reflect.Value, error) {
return reflect.ValueOf(in.Interface().(uuid.UUID).String()), nil
})
model.AddConversion((*string)(nil), (*uuid.UUID)(nil), func(in reflect.Value) (reflect.Value, error) {
return reflect.ValueOf(uuid.FromStringOrNil(in.String())), nil
})
}

// VirtualMachine is *the* VM Definition. It represents a virtual machine in the runtime environment of kubernetes.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -116,63 +104,14 @@ type VirtualMachine struct {
Status VMStatus `json:"status,omitempty"`
}

func (in *VirtualMachine) DeepCopyInto(out *VirtualMachine) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *VirtualMachine) DeepCopy() *VirtualMachine {
if in == nil {
return nil
}
out := new(VirtualMachine)
in.DeepCopyInto(out)
return out
}

func (in *VirtualMachine) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// VirtualMachineList is a list of VirtualMachines
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineList struct {
metav1.TypeMeta `json:",inline"`
ListMeta metav1.ListMeta `json:"metadata,omitempty"`
Items []VirtualMachine `json:"items"`
}

func (in *VirtualMachineList) DeepCopyInto(out *VirtualMachineList) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *VirtualMachineList) DeepCopy() *VirtualMachineList {
if in == nil {
return nil
}
out := new(VirtualMachineList)
in.DeepCopyInto(out)
return out
}

func (in *VirtualMachineList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// VMSpec is a description of a VM. Not to be confused with api.DomainSpec in virt-handler.
// It is expected that v1.DomainSpec will be merged into this structure.
type VMSpec struct {
Expand Down Expand Up @@ -412,31 +351,6 @@ type Spice struct {
Info SpiceInfo `json:"info,omitempty" valid:"required" ini:"virt-viewer"`
}

func (in *Spice) DeepCopyInto(out *Spice) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *Spice) DeepCopy() *Spice {
if in == nil {
return nil
}
out := new(Spice)
in.DeepCopyInto(out)
return out
}

func (in *Spice) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

type SpiceInfo struct {
Type string `json:"type" ini:"type"`
Host string `json:"host" ini:"host"`
Expand Down Expand Up @@ -490,38 +404,14 @@ func NewMigrationReferenceFromName(namespace string, name string) *Migration {
}

// A Migration is a job that moves a Virtual Machine from one node to another
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Migration struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"`
Spec MigrationSpec `json:"spec,omitempty" valid:"required"`
Status MigrationStatus `json:"status,omitempty"`
}

func (in *Migration) DeepCopyInto(out *Migration) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *Migration) DeepCopy() *Migration {
if in == nil {
return nil
}
out := new(Migration)
in.DeepCopyInto(out)
return out
}

func (in *Migration) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// MigrationSpec is a description of a VM Migration
// For example "destinationNodeName": "testvm" will migrate a VM called "testvm" in the namespace "default"
type MigrationSpec struct {
Expand Down Expand Up @@ -593,37 +483,13 @@ func (m *Migration) UnmarshalJSON(data []byte) error {
}

//A list of Migrations
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type MigrationList struct {
metav1.TypeMeta `json:",inline"`
ListMeta metav1.ListMeta `json:"metadata,omitempty"`
Items []Migration `json:"items"`
}

func (in *MigrationList) DeepCopyInto(out *MigrationList) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *MigrationList) DeepCopy() *MigrationList {
if in == nil {
return nil
}
out := new(MigrationList)
in.DeepCopyInto(out)
return out
}

func (in *MigrationList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

// Required to satisfy Object interface
func (ml *MigrationList) GetObjectKind() schema.ObjectKind {
return &ml.TypeMeta
Expand Down Expand Up @@ -700,6 +566,7 @@ func PrepareVMNodeAntiAffinitySelectorRequirement(vm *VirtualMachine) k8sv1.Node
}

// VM is *the* VM Definition. It represents a virtual machine in the runtime environment of kubernetes.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineReplicaSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -710,6 +577,7 @@ type VirtualMachineReplicaSet struct {
}

// VMList is a list of VMs
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type VirtualMachineReplicaSetList struct {
metav1.TypeMeta `json:",inline"`
ListMeta metav1.ListMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -818,53 +686,3 @@ func (vl *VirtualMachineReplicaSetList) GetObjectKind() schema.ObjectKind {
func (vl *VirtualMachineReplicaSetList) GetListMeta() meta.List {
return &vl.ListMeta
}

func (in *VirtualMachineReplicaSet) DeepCopyInto(out *VirtualMachineReplicaSet) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *VirtualMachineReplicaSet) DeepCopy() *VirtualMachineReplicaSet {
if in == nil {
return nil
}
out := new(VirtualMachineReplicaSet)
in.DeepCopyInto(out)
return out
}

func (in *VirtualMachineReplicaSet) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

func (in *VirtualMachineReplicaSetList) DeepCopyInto(out *VirtualMachineReplicaSetList) {
err := model.Copy(out, in)
if err != nil {
panic(err)
}
return
}

func (in *VirtualMachineReplicaSetList) DeepCopy() *VirtualMachineReplicaSetList {
if in == nil {
return nil
}
out := new(VirtualMachineReplicaSetList)
in.DeepCopyInto(out)
return out
}

func (in *VirtualMachineReplicaSetList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
}

0 comments on commit 68f187f

Please sign in to comment.