Skip to content

Commit

Permalink
Fix adding finalizer and update pkgs (#21)
Browse files Browse the repository at this point in the history
* Fix adding finalizer and update pkgs

* Bump k8s deployment to v0.7.1

* Remove apiextensions from RBAC
  • Loading branch information
kairen authored Jul 24, 2019
1 parent 0489778 commit 37ce5e9
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 111 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"syscall"

"github.com/golang/glog"
blended "github.com/inwinstack/blended/client/clientset/versioned"
blended "github.com/inwinstack/blended/generated/clientset/versioned"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/operator"
"github.com/inwinstack/pa-svc-syncker/pkg/version"
Expand Down Expand Up @@ -63,7 +63,7 @@ func parserFlags() {

func restConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig != "" {
cfg, err := clientcmd.BuildConfigFromFlags("master", kubeconfig)
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
serviceAccountName: pa-svc-syncker
containers:
- name: pa-svc-syncker
image: inwinstack/pa-svc-syncker:v0.7.0
image: inwinstack/pa-svc-syncker:v0.7.1
args:
- --v=2
- --logtostderr=true
Expand Down
11 changes: 0 additions & 11 deletions deploy/rbac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ rules:
- namespaces
verbs:
- "*"
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- watch
- update
- create
- delete
- apiGroups:
- inwinstack.com
resources:
Expand Down
44 changes: 13 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,18 @@ module github.com/inwinstack/pa-svc-syncker
go 1.12

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inwinstack/blended v0.6.0
github.com/json-iterator/go v1.1.5 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/pflag v1.0.3
github.com/stretchr/testify v1.3.0
github.com/thoas/go-funk v0.0.0-20181015191849-9132db0aefe2
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b // indirect
golang.org/x/net v0.0.0-20190119204137-ed066c81e75e // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20190123074212-c6b37f3e9285 // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
k8s.io/api v0.0.0-20180628040859-072894a440bd
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d
k8s.io/client-go v8.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20190115222348-ced9eb3070a5 // indirect
github.com/inwinstack/blended v0.7.0
github.com/spf13/pflag v1.0.1
github.com/stretchr/testify v1.2.2
github.com/thoas/go-funk v0.4.0
k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
k8s.io/client-go => k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
)
143 changes: 91 additions & 52 deletions go.sum

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ package constants

const Finalizer = "kubernetes"

const CustomFinalizer = "finalizer.inwinstack.com"

const PolicyPrefix = "k8s"

// Annotation Keys
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/namespace/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/golang/glog"
blended "github.com/inwinstack/blended/client/clientset/versioned"
blended "github.com/inwinstack/blended/generated/clientset/versioned"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/operator/service"
"github.com/thoas/go-funk"
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/namespace/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

blendedv1 "github.com/inwinstack/blended/apis/inwinstack/v1"
blendedfake "github.com/inwinstack/blended/client/clientset/versioned/fake"
blendedfake "github.com/inwinstack/blended/generated/clientset/versioned/fake"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/constants"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"time"

blended "github.com/inwinstack/blended/client/clientset/versioned"
blended "github.com/inwinstack/blended/generated/clientset/versioned"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/operator/namespace"
"github.com/inwinstack/pa-svc-syncker/pkg/operator/service"
Expand Down
11 changes: 7 additions & 4 deletions pkg/operator/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
"time"

"github.com/golang/glog"
blended "github.com/inwinstack/blended/client/clientset/versioned"
blended "github.com/inwinstack/blended/generated/clientset/versioned"
"github.com/inwinstack/blended/k8sutil"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/constants"
"github.com/thoas/go-funk"
Expand Down Expand Up @@ -222,6 +223,10 @@ func (c *Controller) reconcile(key string) error {
}

svcCopy := service.DeepCopy()
if !funk.ContainsString(svcCopy.Finalizers, constants.Finalizer) {
k8sutil.AddFinalizer(&svcCopy.ObjectMeta, constants.Finalizer)
}

if _, err := c.clientset.CoreV1().Services(svcCopy.Namespace).Update(svcCopy); err != nil {
return err
}
Expand Down Expand Up @@ -284,9 +289,7 @@ func (c *Controller) cleanup(svc *v1.Service) error {
}

func (c *Controller) removeFinalizer(svc *v1.Service) error {
svc.ObjectMeta.Finalizers = funk.FilterString(svc.ObjectMeta.Finalizers, func(s string) bool {
return s != constants.Finalizer
})
k8sutil.RemoveFinalizer(&svc.ObjectMeta, constants.Finalizer)
if _, err := c.clientset.CoreV1().Services(svc.Namespace).Update(svc); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/service/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

blendedv1 "github.com/inwinstack/blended/apis/inwinstack/v1"
blendedfake "github.com/inwinstack/blended/client/clientset/versioned/fake"
blendedfake "github.com/inwinstack/blended/generated/clientset/versioned/fake"
"github.com/inwinstack/pa-svc-syncker/pkg/config"
"github.com/inwinstack/pa-svc-syncker/pkg/constants"
"github.com/stretchr/testify/assert"
Expand Down
4 changes: 0 additions & 4 deletions pkg/operator/service/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

blendedv1 "github.com/inwinstack/blended/apis/inwinstack/v1"
"github.com/inwinstack/pa-svc-syncker/pkg/constants"
"github.com/thoas/go-funk"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -50,9 +49,6 @@ func (c *Controller) allocate(svc *v1.Service) error {
if err == nil {
if net.ParseIP(ip.Status.Address) != nil {
svc.Annotations[constants.PublicIPKey] = ip.Status.Address
if !funk.ContainsString(svc.ObjectMeta.Finalizers, constants.Finalizer) {
svc.ObjectMeta.Finalizers = append(svc.ObjectMeta.Finalizers, constants.Finalizer)
}
}
return nil
}
Expand Down

0 comments on commit 37ce5e9

Please sign in to comment.