@@ -10,7 +10,7 @@ import (
1010 "github.com/logicmonitor/k8s-argus/pkg/permission"
1111 "github.com/logicmonitor/k8s-argus/pkg/types"
1212 log "github.com/sirupsen/logrus"
13- "k8s.io/api/apps/v1beta2 "
13+ appsv1 "k8s.io/api/apps/v1 "
1414 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515 "k8s.io/apimachinery/pkg/runtime"
1616 "k8s.io/client-go/kubernetes"
@@ -27,7 +27,7 @@ type Watcher struct {
2727
2828// APIVersion is a function that implements the Watcher interface.
2929func (w * Watcher ) APIVersion () string {
30- return constants .K8sAPIVersionAppsV1beta2
30+ return constants .K8sAPIVersionAppsV1
3131}
3232
3333// Enabled is a function that check the resource can watch.
@@ -42,13 +42,13 @@ func (w *Watcher) Resource() string {
4242
4343// ObjType is a function that implements the Watcher interface.
4444func (w * Watcher ) ObjType () runtime.Object {
45- return & v1beta2 .Deployment {}
45+ return & appsv1 .Deployment {}
4646}
4747
4848// AddFunc is a function that implements the Watcher interface.
4949func (w * Watcher ) AddFunc () func (obj interface {}) {
5050 return func (obj interface {}) {
51- deployment := obj .(* v1beta2 .Deployment )
51+ deployment := obj .(* appsv1 .Deployment )
5252 log .Infof ("Handling add deployment event: %s" , deployment .Name )
5353 w .add (deployment )
5454 }
@@ -57,8 +57,8 @@ func (w *Watcher) AddFunc() func(obj interface{}) {
5757// UpdateFunc is a function that implements the Watcher interface.
5858func (w * Watcher ) UpdateFunc () func (oldObj , newObj interface {}) {
5959 return func (oldObj , newObj interface {}) {
60- old := oldObj .(* v1beta2 .Deployment )
61- new := newObj .(* v1beta2 .Deployment )
60+ old := oldObj .(* appsv1 .Deployment )
61+ new := newObj .(* appsv1 .Deployment )
6262
6363 w .update (old , new )
6464 }
@@ -67,7 +67,7 @@ func (w *Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
6767// DeleteFunc is a function that implements the Watcher interface.
6868func (w * Watcher ) DeleteFunc () func (obj interface {}) {
6969 return func (obj interface {}) {
70- deployment := obj .(* v1beta2 .Deployment )
70+ deployment := obj .(* appsv1 .Deployment )
7171 log .Debugf ("Handling delete deployment event: %s" , deployment .Name )
7272 // Delete the deployment.
7373 if w .Config ().DeleteDevices {
@@ -85,7 +85,7 @@ func (w *Watcher) DeleteFunc() func(obj interface{}) {
8585}
8686
8787// nolint: dupl
88- func (w * Watcher ) add (deployment * v1beta2 .Deployment ) {
88+ func (w * Watcher ) add (deployment * appsv1 .Deployment ) {
8989 if _ , err := w .Add (
9090 w .args (deployment , constants .DeploymentCategory )... ,
9191 ); err != nil {
@@ -95,7 +95,7 @@ func (w *Watcher) add(deployment *v1beta2.Deployment) {
9595 log .Infof ("Added deployment %q" , fmtDeploymentDisplayName (deployment ))
9696}
9797
98- func (w * Watcher ) update (old , new * v1beta2 .Deployment ) {
98+ func (w * Watcher ) update (old , new * appsv1 .Deployment ) {
9999 if _ , err := w .UpdateAndReplaceByDisplayName (
100100 fmtDeploymentDisplayName (old ),
101101 w .args (new , constants .DeploymentCategory )... ,
@@ -106,15 +106,15 @@ func (w *Watcher) update(old, new *v1beta2.Deployment) {
106106 log .Infof ("Updated deployment %q" , fmtDeploymentDisplayName (old ))
107107}
108108
109- func (w * Watcher ) move (deployment * v1beta2 .Deployment ) {
109+ func (w * Watcher ) move (deployment * appsv1 .Deployment ) {
110110 if _ , err := w .UpdateAndReplaceFieldByDisplayName (fmtDeploymentDisplayName (deployment ), constants .CustomPropertiesFieldName , w .args (deployment , constants .DeploymentDeletedCategory )... ); err != nil {
111111 log .Errorf ("Failed to move deployment %q: %v" , fmtDeploymentDisplayName (deployment ), err )
112112 return
113113 }
114114 log .Infof ("Moved deployment %q" , fmtDeploymentDisplayName (deployment ))
115115}
116116
117- func (w * Watcher ) args (deployment * v1beta2 .Deployment , category string ) []types.DeviceOption {
117+ func (w * Watcher ) args (deployment * appsv1 .Deployment , category string ) []types.DeviceOption {
118118 return []types.DeviceOption {
119119 w .Name (deployment .Name ),
120120 w .ResourceLabels (deployment .Labels ),
@@ -130,14 +130,14 @@ func (w *Watcher) args(deployment *v1beta2.Deployment, category string) []types.
130130}
131131
132132// fmtDeploymentDisplayName implements the conversion for the deployment display name
133- func fmtDeploymentDisplayName (deployment * v1beta2 .Deployment ) string {
133+ func fmtDeploymentDisplayName (deployment * appsv1 .Deployment ) string {
134134 return fmt .Sprintf ("%s.%s.deploy-%s" , deployment .Name , deployment .Namespace , string (deployment .UID ))
135135}
136136
137137// GetDeploymentsMap implements the getting deployments map info from k8s
138138func GetDeploymentsMap (k8sClient * kubernetes.Clientset , namespace string ) (map [string ]string , error ) {
139139 deploymentsMap := make (map [string ]string )
140- deploymentList , err := k8sClient .AppsV1beta2 ().Deployments (namespace ).List (v1.ListOptions {})
140+ deploymentList , err := k8sClient .AppsV1 ().Deployments (namespace ).List (v1.ListOptions {})
141141 if err != nil || deploymentList == nil {
142142 log .Warnf ("Failed to get the deployments from k8s" )
143143 return nil , err
0 commit comments