Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kubernetes/code-generator #215

Merged
merged 4 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 0 additions & 25 deletions api/install/install.go

This file was deleted.

31 changes: 0 additions & 31 deletions api/register_v1alpha1.go

This file was deleted.

5 changes: 5 additions & 0 deletions apis/monitoring/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// package monitoring is the internal version of the API.

// +k8s:deepcopy-gen=package,register
// +groupName=monitoring.appscode.com
package monitoring
28 changes: 28 additions & 0 deletions apis/monitoring/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package install

import (
tapi "github.com/appscode/searchlight/apis/monitoring"
"github.com/appscode/searchlight/apis/monitoring/v1alpha1"
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
)

// 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: tapi.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "gitub.com/appscode/searchlight/apis/monitoring",
RootScopedKinds: sets.NewString("CustomResourceDefinition"),
AddInternalObjectsToScheme: tapi.AddToScheme,
},
announced.VersionToSchemeFunc{
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
},
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err)
}
}
27 changes: 8 additions & 19 deletions api/register.go → apis/monitoring/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package monitoring

import (
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -11,12 +11,12 @@ const GroupName = "monitoring.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,26 +26,15 @@ 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,
&PodAlert{},
&PodAlertList{},

&NodeAlert{},
&NodeAlertList{},

&ClusterAlert{},
&ClusterAlertList{},
&NodeAlert{},
&NodeAlertList{},
&PodAlert{},
&PodAlertList{},
)
return nil
}

func (a *PodAlert) GetObjectKind() schema.ObjectKind { return &a.TypeMeta }
func (obj *PodAlertList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

func (a *NodeAlert) GetObjectKind() schema.ObjectKind { return &a.TypeMeta }
func (obj *NodeAlertList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

func (a *ClusterAlert) GetObjectKind() schema.ObjectKind { return &a.TypeMeta }
func (obj *ClusterAlertList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
20 changes: 16 additions & 4 deletions api/types.go → apis/monitoring/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package api
package monitoring

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

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

type ClusterAlert struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
Expand Down Expand Up @@ -49,7 +51,11 @@ type ClusterAlertSpec struct {
Vars map[string]interface{} `json:"vars,omitempty"`
}

// NodeAlert types for appscode.
type CheckCluster string

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

type NodeAlert struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
Expand Down Expand Up @@ -98,7 +104,11 @@ type NodeAlertSpec struct {
Vars map[string]interface{} `json:"vars,omitempty"`
}

// PodAlert types for appscode.
type CheckNode string

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

type PodAlert struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
Expand Down Expand Up @@ -147,6 +157,8 @@ type PodAlertSpec struct {
Vars map[string]interface{} `json:"vars,omitempty"`
}

type CheckPod string

type Receiver struct {
// For which state notification will be sent
State string `json:"state,omitempty"`
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/alert.go → apis/monitoring/v1alpha1/alert.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package v1alpha1

import "time"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package v1alpha1

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

// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/appscode/searchlight/apis/monitoring
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +groupName=monitoring.appscode.com
package v1alpha1
2 changes: 1 addition & 1 deletion api/icinga.go → apis/monitoring/v1alpha1/icinga.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package v1alpha1

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package api
package v1alpha1

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

import (
"fmt"
Expand Down
48 changes: 48 additions & 0 deletions apis/monitoring/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v1alpha1

import (
"github.com/appscode/searchlight/apis/monitoring"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var SchemeGroupVersion = schema.GroupVersion{Group: monitoring.GroupName, Version: "v1alpha1"}

var (
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ClusterAlert{},
&ClusterAlertList{},
&NodeAlert{},
&NodeAlertList{},
&PodAlert{},
&PodAlertList{},
)

scheme.AddKnownTypes(SchemeGroupVersion,
&metav1.Status{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
Loading