Skip to content

Commit

Permalink
Use kubernetes/code-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Sep 9, 2017
1 parent 479f0d3 commit c58fd2a
Show file tree
Hide file tree
Showing 158 changed files with 7,772 additions and 1,050 deletions.
25 changes: 0 additions & 25 deletions api/install/install.go

This file was deleted.

28 changes: 0 additions & 28 deletions api/register_v1beta1.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/annotations.go → apis/voyager/annotations.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"testing"
Expand Down
7 changes: 6 additions & 1 deletion api/certificate.go → apis/voyager/certificate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -11,6 +11,9 @@ const (
ResourceTypeCertificate = "certificates"
)

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

type Certificate struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -58,6 +61,8 @@ type ACMECertificateDetails struct {
AccountRef string `json:"accountRef,omitempty"`
}

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

type CertificateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
41 changes: 41 additions & 0 deletions apis/voyager/conversion_v1beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package voyager

import (
"encoding/json"

extensions "k8s.io/client-go/pkg/apis/extensions/v1beta1"
)

func NewEngressFromIngress(ing interface{}) (*Ingress, error) {
data, err := json.Marshal(ing)
if err != nil {
return nil, err
}
r := &Ingress{}
err = json.Unmarshal(data, r)
if err != nil {
return nil, err
}
if r.Annotations == nil {
r.Annotations = make(map[string]string)
}
r.Annotations[APISchema] = APISchemaIngress
return r, nil
}

func NewIngressFromEngress(ing interface{}) (*extensions.Ingress, error) {
data, err := json.Marshal(ing)
if err != nil {
return nil, err
}
r := &extensions.Ingress{}
err = json.Unmarshal(data, r)
if err != nil {
return nil, err
}
if r.Annotations == nil {
r.Annotations = make(map[string]string)
}
r.Annotations[APISchema] = APISchemaEngress
return r, nil
}
File renamed without changes.
2 changes: 1 addition & 1 deletion api/diff.go → apis/voyager/diff.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion api/diff_test.go → apis/voyager/diff_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion api/dns_resolver.go → apis/voyager/dns_resolver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"fmt"
Expand Down
5 changes: 5 additions & 0 deletions apis/voyager/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Package voyager is the internal version of the API.

// +k8s:deepcopy-gen=package,register
// +groupName=voyager.appscode.com
package voyager
7 changes: 6 additions & 1 deletion api/ingress.go → apis/voyager/ingress.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -12,6 +12,9 @@ const (
ResourceTypeIngress = "ingresses"
)

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

// Custom Ingress type for Voyager.
type Ingress struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -28,6 +31,8 @@ type Ingress struct {
Status IngressStatus `json:"status,omitempty"`
}

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

// IngressList is a collection of Ingress.
type IngressList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
26 changes: 26 additions & 0 deletions apis/voyager/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package install

import (
sapi "github.com/appscode/voyager/apis/voyager"
"github.com/appscode/voyager/apis/voyager/v1beta1"
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime"
)

// Install registers the API group and adds types to a scheme
func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: sapi.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "github.com/appscode/voyager/apis/voyager",
AddInternalObjectsToScheme: sapi.AddToScheme,
},
announced.VersionToSchemeFunc{
v1beta1.SchemeGroupVersion.Version: v1beta1.AddToScheme,
},
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion api/monitor.go → apis/voyager/monitor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion api/port.go → apis/voyager/port.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"fmt"
Expand Down
20 changes: 7 additions & 13 deletions api/register.go → apis/voyager/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package voyager

import (
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -11,12 +11,12 @@ const GroupName = "voyager.appscode.com"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns back a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand All @@ -26,20 +26,14 @@ var (
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to apiv1.Scheme.
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Ingress{},
&IngressList{},

&Certificate{},
&CertificateList{},

&Ingress{},
&IngressList{},
)
return nil
}

func (r *Ingress) GetObjectKind() schema.ObjectKind { return &r.TypeMeta }
func (obj *IngressList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

func (obj *Certificate) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *CertificateList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
Loading

0 comments on commit c58fd2a

Please sign in to comment.