Skip to content

Commit

Permalink
Remove dependency on k8s-addons (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Jun 2, 2017
1 parent dd107b0 commit b24d3d1
Show file tree
Hide file tree
Showing 55 changed files with 323 additions and 1,124 deletions.
Expand Up @@ -12,7 +12,7 @@ import (
func addConversionFuncs(scheme *runtime.Scheme) error {
// Add field label conversions for kinds having selectable nothing but ObjectMeta fields.
var err error
for _, k := range []string{"Ingress", "Alert", "Backup", "Certificate"} {
for _, k := range []string{"Ingress", "Certificate"} {
kind := k // don't close over range variables
err = api.Scheme.AddFieldLabelConversionFunc("appscode.com/v1", kind,
func(label, value string) (string, string, error) {
Expand Down
7 changes: 7 additions & 0 deletions api/extensions/certificate.yaml
@@ -0,0 +1,7 @@
metadata:
name: certificate.appscode.com
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
description: "A specification of a Let's Encrypt Certificate to manage."
versions:
- name: v1beta1
7 changes: 7 additions & 0 deletions api/extensions/ingress.yaml
@@ -0,0 +1,7 @@
metadata:
name: ingress.appscode.com
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
description: "Extended ingress support for Kubernetes by appscode.com"
versions:
- name: v1beta1
@@ -1,7 +1,7 @@
package install

import (
aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"k8s.io/kubernetes/pkg/apimachinery/announced"
"k8s.io/kubernetes/pkg/util/sets"
)
Expand All @@ -11,8 +11,8 @@ func init() {
&announced.GroupMetaFactoryArgs{
GroupName: aci.GroupName,
VersionPreferenceOrder: []string{aci.V1beta1SchemeGroupVersion.Version},
ImportPrefix: "github.com/appscode/k8s-addons/api",
RootScopedKinds: sets.NewString("PodSecurityPolicy", "ThirdPartyResource"),
ImportPrefix: "github.com/appscode/voyager/api",
RootScopedKinds: sets.NewString("ThirdPartyResource"),
AddInternalObjectsToScheme: aci.AddToScheme,
},
announced.VersionToSchemeFunc{
Expand Down
12 changes: 0 additions & 12 deletions ...b.com/appscode/k8s-addons/api/register.go → api/register.go
Expand Up @@ -33,15 +33,9 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&Ingress{},
&IngressList{},

&Alert{},
&AlertList{},

&Certificate{},
&CertificateList{},

&Backup{},
&BackupList{},

&api.ListOptions{},
)
return nil
Expand All @@ -50,11 +44,5 @@ func addKnownTypes(scheme *runtime.Scheme) error {
func (obj *Ingress) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *IngressList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

func (obj *Alert) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *AlertList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

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

func (obj *Backup) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
func (obj *BackupList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
Expand Up @@ -21,15 +21,9 @@ func v1addKnownTypes(scheme *runtime.Scheme) error {
&Ingress{},
&IngressList{},

&Alert{},
&AlertList{},

&Certificate{},
&CertificateList{},

&Backup{},
&BackupList{},

&v1.ListOptions{},
)
versionedwatch.AddToGroupVersion(scheme, V1beta1SchemeGroupVersion)
Expand Down
File renamed without changes.
@@ -1,7 +1,7 @@
package clientset

import (
aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"k8s.io/kubernetes/pkg/api"
rest "k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/watch"
Expand All @@ -26,7 +26,9 @@ type CertificateImpl struct {
ns string
}

func newCertificate(c *AppsCodeExtensionsClient, namespace string) *CertificateImpl {
var _ CertificateInterface = &CertificateImpl{}

func newCertificate(c *ExtensionClient, namespace string) *CertificateImpl {
return &CertificateImpl{c.restClient, namespace}
}

Expand Down
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"strings"

aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"github.com/appscode/log"
"github.com/ghodss/yaml"
"k8s.io/kubernetes/pkg/api"
Expand Down
47 changes: 47 additions & 0 deletions client/clientset/codec_test.go
@@ -0,0 +1,47 @@
package clientset

import (
"fmt"
"reflect"
"testing"

aci "github.com/appscode/voyager/api"
"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/runtime"
)

func TestDefaultGroupVersion(t *testing.T) {
i := &aci.Ingress{
ObjectMeta: api.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
}

gv, err := unversioned.ParseGroupVersion("appscode.com/v1beta1")
if err != nil {
fmt.Println(err)
}
// if appscode.com/v1beta1 is not enabled, return an error
if !registered.IsEnabledVersion(gv) {
fmt.Println("appscode.com/v1beta1 is not enabled")
}

fmt.Println(*i)
}

func TestSetDefault(t *testing.T) {
metadata := &unversioned.TypeMeta{
Kind: "Ingress",
APIVersion: "appscode.com/v1beta1",
}
var obj runtime.Object

obj, err := setDefaultType(metadata)
fmt.Println(obj, err)
assert.NotNil(t, obj)
fmt.Println(reflect.ValueOf(obj).Type().String())
}
Expand Up @@ -12,42 +12,34 @@ const (
defaultAPIPath = "/apis"
)

type AppsCodeExtensionInterface interface {
type ExtensionInterface interface {
RESTClient() rest.Interface
IngressNamespacer
AlertNamespacer
CertificateNamespacer
BackupNamespacer
}

// AppsCodeExtensionsClient is used to interact with experimental Kubernetes features.
// ExtensionClient is used to interact with experimental Kubernetes features.
// Features of Extensions group are not supported and may be changed or removed in
// incompatible ways at any time.
type AppsCodeExtensionsClient struct {
type ExtensionClient struct {
restClient rest.Interface
}

func (a *AppsCodeExtensionsClient) Ingress(namespace string) IngressInterface {
return newExtendedIngress(a, namespace)
}

func (a *AppsCodeExtensionsClient) Alert(namespace string) AlertInterface {
return newAlert(a, namespace)
}
var _ ExtensionInterface = &ExtensionClient{}

func (a *AppsCodeExtensionsClient) Certificate(namespace string) CertificateInterface {
return newCertificate(a, namespace)
func (c *ExtensionClient) Ingress(namespace string) IngressInterface {
return newExtendedIngress(c, namespace)
}

func (a *AppsCodeExtensionsClient) Backups(namespace string) BackupInterface {
return newBackup(a, namespace)
func (c *ExtensionClient) Certificate(namespace string) CertificateInterface {
return newCertificate(c, namespace)
}

// NewAppsCodeExtensions creates a new AppsCodeExtensionsClient for the given config. This client
// NewForConfig creates a new ExtensionClient for the given config. This client
// provides access to experimental Kubernetes features.
// Features of Extensions group are not supported and may be changed or removed in
// incompatible ways at any time.
func NewACExtensionsForConfig(c *rest.Config) (*AppsCodeExtensionsClient, error) {
func NewForConfig(c *rest.Config) (*ExtensionClient, error) {
config := *c
if err := setExtensionsDefaults(&config); err != nil {
return nil, err
Expand All @@ -56,24 +48,24 @@ func NewACExtensionsForConfig(c *rest.Config) (*AppsCodeExtensionsClient, error)
if err != nil {
return nil, err
}
return &AppsCodeExtensionsClient{client}, nil
return &ExtensionClient{client}, nil
}

// NewAppsCodeExtensionsOrDie creates a new AppsCodeExtensionsClient for the given config and
// NewForConfigOrDie creates a new ExtensionClient for the given config and
// panics if there is an error in the config.
// Features of Extensions group are not supported and may be changed or removed in
// incompatible ways at any time.
func NewACExtensionsForConfigOrDie(c *rest.Config) *AppsCodeExtensionsClient {
client, err := NewACExtensionsForConfig(c)
func NewForConfigOrDie(c *rest.Config) *ExtensionClient {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}

// New creates a new ExtensionsV1beta1Client for the given RESTClient.
func NewNewACExtensions(c rest.Interface) *AppsCodeExtensionsClient {
return &AppsCodeExtensionsClient{c}
// New creates a new ExtensionClient for the given RESTClient.
func New(c rest.Interface) *ExtensionClient {
return &ExtensionClient{c}
}

func setExtensionsDefaults(config *rest.Config) error {
Expand Down Expand Up @@ -106,7 +98,7 @@ func setExtensionsDefaults(config *rest.Config) error {

// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *AppsCodeExtensionsClient) RESTClient() rest.Interface {
func (c *ExtensionClient) RESTClient() rest.Interface {
if c == nil {
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions client/clientset/fake/README.md
@@ -0,0 +1,3 @@
## fakes

This package is a fake kube resource implementation. Should Only be used for Testing purpose.
@@ -1,12 +1,13 @@
package fake

import (
aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"k8s.io/kubernetes/pkg/api"
schema "k8s.io/kubernetes/pkg/api/unversioned"
testing "k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
"github.com/appscode/voyager/client/clientset"
)

type FakeCertificate struct {
Expand All @@ -16,6 +17,8 @@ type FakeCertificate struct {

var certResource = schema.GroupVersionResource{Group: "appscode.com", Version: "v1beta1", Resource: "certificates"}

var _ clientset.CertificateInterface = &FakeCertificate{}

// Get returns the Certificate by name.
func (mock *FakeCertificate) Get(name string) (*aci.Certificate, error) {
obj, err := mock.Fake.
Expand Down
@@ -1,7 +1,7 @@
package fake

import (
"github.com/appscode/k8s-addons/client/clientset"
"github.com/appscode/voyager/client/clientset"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apimachinery/registered"
rest "k8s.io/kubernetes/pkg/client/restclient"
Expand All @@ -14,7 +14,7 @@ type FakeExtensionClient struct {
*testing.Fake
}

var _ clientset.AppsCodeExtensionInterface = &FakeExtensionClient{}
var _ clientset.ExtensionInterface = &FakeExtensionClient{}

func NewFakeExtensionClient(objects ...runtime.Object) *FakeExtensionClient {
o := testing.NewObjectTracker(api.Scheme, api.Codecs.UniversalDecoder())
Expand All @@ -34,20 +34,12 @@ func NewFakeExtensionClient(objects ...runtime.Object) *FakeExtensionClient {
return &FakeExtensionClient{&fakePtr}
}

func (a *FakeExtensionClient) Ingress(namespace string) clientset.IngressInterface {
return &FakeIngress{a.Fake, namespace}
func (c *FakeExtensionClient) Ingress(namespace string) clientset.IngressInterface {
return &FakeIngress{c.Fake, namespace}
}

func (a *FakeExtensionClient) Alert(namespace string) clientset.AlertInterface {
return &FakeAlert{a.Fake, namespace}
}

func (m *FakeExtensionClient) Certificate(ns string) clientset.CertificateInterface {
return &FakeCertificate{m.Fake, ns}
}

func (m *FakeExtensionClient) Backups(ns string) clientset.BackupInterface {
return &FakeBackup{m.Fake, ns}
func (c *FakeExtensionClient) Certificate(ns string) clientset.CertificateInterface {
return &FakeCertificate{c.Fake, ns}
}

// RESTClient returns a RESTClient that is used to communicate
Expand Down
@@ -1,12 +1,13 @@
package fake

import (
aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"k8s.io/kubernetes/pkg/api"
schema "k8s.io/kubernetes/pkg/api/unversioned"
testing "k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
"github.com/appscode/voyager/client/clientset"
)

type FakeIngress struct {
Expand All @@ -16,6 +17,8 @@ type FakeIngress struct {

var ingressResource = schema.GroupVersionResource{Group: "appscode.com", Version: "v1beta1", Resource: "ingresses"}

var _ clientset.IngressInterface = &FakeIngress{}

// Get returns the Ingress by name.
func (mock *FakeIngress) Get(name string) (*aci.Ingress, error) {
obj, err := mock.Fake.
Expand Down
Expand Up @@ -4,7 +4,7 @@ package clientset
import (
"fmt"

_ "github.com/appscode/k8s-addons/api/install"
_ "github.com/appscode/voyager/api/install"
_ "k8s.io/kubernetes/pkg/api/install"
"k8s.io/kubernetes/pkg/apimachinery/registered"
_ "k8s.io/kubernetes/pkg/apis/apps/install"
Expand Down
@@ -1,7 +1,7 @@
package clientset

import (
aci "github.com/appscode/k8s-addons/api"
aci "github.com/appscode/voyager/api"
"k8s.io/kubernetes/pkg/api"
rest "k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/watch"
Expand Down Expand Up @@ -29,8 +29,10 @@ type IngressImpl struct {
ns string
}

var _ IngressInterface = &IngressImpl{}

// newExtendedIngress returns a ExtendedIngress
func newExtendedIngress(c *AppsCodeExtensionsClient, namespace string) *IngressImpl {
func newExtendedIngress(c *ExtensionClient, namespace string) *IngressImpl {
return &IngressImpl{c.restClient, namespace}
}

Expand Down

0 comments on commit b24d3d1

Please sign in to comment.