Skip to content

Commit

Permalink
feat: log to the operator's log
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Jan 23, 2020
1 parent 4b4c487 commit edccc89
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 42 deletions.
10 changes: 0 additions & 10 deletions cmd/kubedb-capability/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@ import (
"halkyon.io/kubedb-capability/pkg/plugin/mysql"
"halkyon.io/kubedb-capability/pkg/plugin/postgresql"
plugins "halkyon.io/operator-framework/plugins/capability"
"log"
"os"
"path/filepath"
)

func main() {
pluginName := filepath.Base(os.Args[0])
f, err := os.OpenFile(pluginName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
log.SetOutput(f)

plugins.StartPluginServerFor(postgresql.NewPluginResource(), mysql.NewPluginResource(), mongodb.NewPluginResource())
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module halkyon.io/kubedb-capability
go 1.13

require (
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
halkyon.io/api v1.0.0-rc.3
halkyon.io/operator-framework v1.0.0-beta.3
halkyon.io/operator-framework v1.0.0-beta.3.0.20200123132453-20459cfad8a3
k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2
k8s.io/apimachinery v0.17.0
kmodules.xyz/offshoot-api v0.0.0-20190901210649-de049192326c
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ github.com/appscode/go v0.0.0-20191006073906-e3d193d493fc/go.mod h1:hUW7Fq0KY2/n
github.com/appscode/go v0.0.0-20191016085057-e186b6c94a3b/go.mod h1:hUW7Fq0KY2/ntGnYAzemyUpIhLL6bXrTljN6SRY/+Lc=
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef h1:nTbtvdVAVwFgKANCR4KU36Jo1V9Xs/Z2GMEAlpOVG1Y=
github.com/appscode/go v0.0.0-20191025021232-311ac347b3ef/go.mod h1:hUW7Fq0KY2/ntGnYAzemyUpIhLL6bXrTljN6SRY/+Lc=
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc h1:Q5jwbRq/a1Tien+Is8Zn6HMBRgE13+UOQ9mTvrIuvuE=
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE=
github.com/appscode/osm v0.12.0/go.mod h1:M2dkG7yApVG4hWvRli6FgDxYItfkkN7jZditR2AAvdA=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down Expand Up @@ -811,6 +813,8 @@ halkyon.io/api v1.0.0-rc.3 h1:evcR0y3QEXwLdYY9z1PKBZIXgsuxu//M81fEVGwLjGU=
halkyon.io/api v1.0.0-rc.3/go.mod h1:bCOZh54+rJ4SQad0L0OMO0B+Jf7J3OtKp7SPmdLowGE=
halkyon.io/operator-framework v1.0.0-beta.3 h1:sVZKZcHYs6iUYfDqzyCzzHjTMUFIoj8/a7XiLEAS4v4=
halkyon.io/operator-framework v1.0.0-beta.3/go.mod h1:sOn1iLYLTQ9JmoVdZ7WNvhlCDVPLYRBKnaxYBMJQ3OI=
halkyon.io/operator-framework v1.0.0-beta.3.0.20200123132453-20459cfad8a3 h1:kAHFnbRBGvnDinRKMBYUEKjqiaSv56jLjerc0si9EiI=
halkyon.io/operator-framework v1.0.0-beta.3.0.20200123132453-20459cfad8a3/go.mod h1:sOn1iLYLTQ9JmoVdZ7WNvhlCDVPLYRBKnaxYBMJQ3OI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
23 changes: 14 additions & 9 deletions pkg/plugin/mongodb/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mongodb

import (
"github.com/appscode/go/strings"
"github.com/hashicorp/go-hclog"
"halkyon.io/api/capability/v1beta1"
beta1 "halkyon.io/api/v1beta1"
"halkyon.io/kubedb-capability/pkg/plugin"
Expand All @@ -14,7 +15,7 @@ import (
var _ capability.PluginResource = &MongoDBPluginResource{}

type MongoDBPluginResource struct {
capability.SimplePluginResourceStem
capability.QueryingSimplePluginResourceStem
}

func (m MongoDBPluginResource) GetDependentResourcesWith(owner beta1.HalkyonResource) []framework.DependentResource {
Expand All @@ -26,19 +27,23 @@ func (m MongoDBPluginResource) GetDependentResourcesWith(owner beta1.HalkyonReso
}

func NewPluginResource() capability.PluginResource {
return &MongoDBPluginResource{capability.NewQueryingSimplePluginResourceStem(v1beta1.DatabaseCategory, resolver)}
}

func resolver(logger hclog.Logger) capability.TypeInfo {
list, err := plugin.Client.MongoDBVersions().List(v1.ListOptions{})
versions := []string{}
if err == nil {
versions = make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
if err != nil {
logger.Error("error retrieving versions: %v", err)
}
versions := make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
}
info := capability.TypeInfo{
Type: kubedbv1.ResourceKindMongoDB,
Versions: versions,
}
return &MongoDBPluginResource{capability.NewSimplePluginResourceStem(v1beta1.DatabaseCategory, info)}
return info
}
23 changes: 14 additions & 9 deletions pkg/plugin/mysql/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mysql

import (
"github.com/appscode/go/strings"
"github.com/hashicorp/go-hclog"
"halkyon.io/api/capability/v1beta1"
beta1 "halkyon.io/api/v1beta1"
"halkyon.io/kubedb-capability/pkg/plugin"
Expand All @@ -14,7 +15,7 @@ import (
var _ capability.PluginResource = &MySQLPluginResource{}

type MySQLPluginResource struct {
capability.SimplePluginResourceStem
capability.QueryingSimplePluginResourceStem
}

func (m MySQLPluginResource) GetDependentResourcesWith(owner beta1.HalkyonResource) []framework.DependentResource {
Expand All @@ -26,19 +27,23 @@ func (m MySQLPluginResource) GetDependentResourcesWith(owner beta1.HalkyonResour
}

func NewPluginResource() capability.PluginResource {
return &MySQLPluginResource{capability.NewQueryingSimplePluginResourceStem(v1beta1.DatabaseCategory, resolver)}
}

func resolver(logger hclog.Logger) capability.TypeInfo {
list, err := plugin.Client.MySQLVersions().List(v1.ListOptions{})
versions := []string{}
if err == nil {
versions = make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
if err != nil {
logger.Error("error retrieving versions: %v", err)
}
versions := make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
}
info := capability.TypeInfo{
Type: kubedbv1.ResourceKindMySQL,
Versions: versions,
}
return &MySQLPluginResource{capability.NewSimplePluginResourceStem(v1beta1.DatabaseCategory, info)}
return info
}
24 changes: 12 additions & 12 deletions pkg/plugin/postgresql/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@ package postgresql

import (
"github.com/appscode/go/strings"
"github.com/hashicorp/go-hclog"
"halkyon.io/api/capability/v1beta1"
v1beta12 "halkyon.io/api/v1beta1"
"halkyon.io/kubedb-capability/pkg/plugin"
"halkyon.io/operator-framework"
"halkyon.io/operator-framework/plugins/capability"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubedbv1 "kubedb.dev/apimachinery/apis/kubedb/v1alpha1"
"log"
)

var _ capability.PluginResource = &PostgresPluginResource{}

func NewPluginResource() capability.PluginResource {
log.Println("Starting Postgres support")
return &PostgresPluginResource{capability.NewQueryingSimplePluginResourceStem(v1beta1.DatabaseCategory, resolver)}
}

func resolver(logger hclog.Logger) capability.TypeInfo {
list, err := plugin.Client.PostgresVersions().List(v1.ListOptions{})
if err != nil {
log.Printf("error retrieving versions: %v", err)
logger.Error("error retrieving versions: %v", err)
}
versions := []string{}
if err == nil {
versions = make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
versions := make([]string, 0, len(list.Items))
for _, version := range list.Items {
if !version.Spec.Deprecated && !strings.Contains(versions, version.Spec.Version) {
versions = append(versions, version.Spec.Version)
}
}
info := capability.TypeInfo{
Type: kubedbv1.ResourceKindPostgres,
Versions: versions,
}
return &PostgresPluginResource{capability.NewSimplePluginResourceStem(v1beta1.DatabaseCategory, info)}
return info
}

type PostgresPluginResource struct {
capability.SimplePluginResourceStem
capability.QueryingSimplePluginResourceStem
}

func (p *PostgresPluginResource) GetDependentResourcesWith(owner v1beta12.HalkyonResource) []framework.DependentResource {
Expand Down

0 comments on commit edccc89

Please sign in to comment.