Skip to content

Commit

Permalink
Merge pull request #142 from flant/fix_1_16
Browse files Browse the repository at this point in the history
fix: k8s 1.16 has dropped extensions/v1beta1 and use apps/v1 for ds, deploy and replicaset objects
  • Loading branch information
distorhead authored Sep 23, 2019
2 parents 6b60dad + c769faf commit 0c24f4c
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 190 deletions.
19 changes: 6 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
module github.com/flant/kubedog

require (
github.com/Azure/go-autorest v11.1.0+incompatible // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/fatih/color v1.7.0
github.com/flant/logboek v0.2.6-0.20190726104558-c32b60bb4a37
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.6 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529
golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914 // indirect
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
k8s.io/api v0.0.0-20190409092523-d687e77c8ae9
k8s.io/apimachinery v0.0.0-20190409092423-760d1845f48b
k8s.io/client-go v0.0.0-20190411052641-7a6b4715b709
k8s.io/klog v0.2.0
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
k8s.io/klog v0.4.0
)
199 changes: 122 additions & 77 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/tracker/daemonset/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"strings"

"github.com/flant/kubedog/pkg/tracker/debug"
extensions "k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
)

func getDaemonSetStatus(obj *extensions.DaemonSet) string {
func getDaemonSetStatus(obj *appsv1.DaemonSet) string {
msgs := []string{}

for _, c := range obj.Status.Conditions {
Expand Down
14 changes: 7 additions & 7 deletions pkg/tracker/daemonset/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/flant/kubedog/pkg/tracker/indicators"
"github.com/flant/kubedog/pkg/tracker/pod"
extensions "k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
)

type DaemonSetStatus struct {
extensions.DaemonSetStatus
appsv1.DaemonSetStatus

StatusGeneration uint64

Expand All @@ -27,7 +27,7 @@ type DaemonSetStatus struct {
NewPodsNames []string
}

func NewDaemonSetStatus(object *extensions.DaemonSet, statusGeneration uint64, isTrackerFailed bool, trackerFailedReason string, podsStatuses map[string]pod.PodStatus, newPodsNames []string) DaemonSetStatus {
func NewDaemonSetStatus(object *appsv1.DaemonSet, statusGeneration uint64, isTrackerFailed bool, trackerFailedReason string, podsStatuses map[string]pod.PodStatus, newPodsNames []string) DaemonSetStatus {
res := DaemonSetStatus{
StatusGeneration: statusGeneration,
DaemonSetStatus: object.Status,
Expand Down Expand Up @@ -58,7 +58,7 @@ processingPodsStatuses:
res.IsReady = false

// FIXME: tracker should track other update strategy types as well
if object.Spec.UpdateStrategy.Type != extensions.RollingUpdateDaemonSetStrategyType {
if object.Spec.UpdateStrategy.Type != appsv1.RollingUpdateDaemonSetStrategyType {
res.IsReady = true
return res
}
Expand Down Expand Up @@ -100,9 +100,9 @@ processingPodsStatuses:
}

// Status returns a message describing daemon set status, and a bool value indicating if the status is considered done.
func DaemonSetRolloutStatus(daemon *extensions.DaemonSet) (string, bool, error) {
if daemon.Spec.UpdateStrategy.Type != extensions.RollingUpdateDaemonSetStrategyType {
return "", true, fmt.Errorf("rollout status is only available for %s strategy type", extensions.RollingUpdateDaemonSetStrategyType)
func DaemonSetRolloutStatus(daemon *appsv1.DaemonSet) (string, bool, error) {
if daemon.Spec.UpdateStrategy.Type != appsv1.RollingUpdateDaemonSetStrategyType {
return "", true, fmt.Errorf("rollout status is only available for %s strategy type", appsv1.RollingUpdateDaemonSetStrategyType)
}
if daemon.Generation <= daemon.Status.ObservedGeneration {
if daemon.Status.UpdatedNumberScheduled < daemon.Status.DesiredNumberScheduled {
Expand Down
32 changes: 16 additions & 16 deletions pkg/tracker/daemonset/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -29,10 +29,10 @@ type Tracker struct {

State string
Conditions []string
FinalDaemonSetStatus extensions.DaemonSetStatus
FinalDaemonSetStatus appsv1.DaemonSetStatus
CurrentReady bool

lastObject *extensions.DaemonSet
lastObject *appsv1.DaemonSet
statusGeneration uint64
failedReason string
podStatuses map[string]pod.PodStatus
Expand All @@ -51,9 +51,9 @@ type Tracker struct {
PodError chan replicaset.ReplicaSetPodError
StatusReport chan DaemonSetStatus

resourceAdded chan *extensions.DaemonSet
resourceModified chan *extensions.DaemonSet
resourceDeleted chan *extensions.DaemonSet
resourceAdded chan *appsv1.DaemonSet
resourceModified chan *appsv1.DaemonSet
resourceDeleted chan *appsv1.DaemonSet
resourceFailed chan string
podAdded chan *corev1.Pod
podDone chan string
Expand Down Expand Up @@ -91,9 +91,9 @@ func NewTracker(ctx context.Context, name, namespace string, kube kubernetes.Int
podStatuses: make(map[string]pod.PodStatus),
podGenerations: make(map[string]string),

resourceAdded: make(chan *extensions.DaemonSet, 1),
resourceModified: make(chan *extensions.DaemonSet, 1),
resourceDeleted: make(chan *extensions.DaemonSet, 1),
resourceAdded: make(chan *appsv1.DaemonSet, 1),
resourceModified: make(chan *appsv1.DaemonSet, 1),
resourceDeleted: make(chan *appsv1.DaemonSet, 1),
resourceFailed: make(chan string, 1),
podAdded: make(chan *corev1.Pod, 1),
podDone: make(chan string, 1),
Expand Down Expand Up @@ -238,26 +238,26 @@ func (d *Tracker) runDaemonSetInformer() {
}
lw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return client.ExtensionsV1beta1().DaemonSets(d.Namespace).List(tweakListOptions(options))
return client.AppsV1().DaemonSets(d.Namespace).List(tweakListOptions(options))
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return client.ExtensionsV1beta1().DaemonSets(d.Namespace).Watch(tweakListOptions(options))
return client.AppsV1().DaemonSets(d.Namespace).Watch(tweakListOptions(options))
},
}

go func() {
_, err := watchtools.UntilWithSync(d.Context, lw, &extensions.DaemonSet{}, nil, func(e watch.Event) (bool, error) {
_, err := watchtools.UntilWithSync(d.Context, lw, &appsv1.DaemonSet{}, nil, func(e watch.Event) (bool, error) {
if debug.Debug() {
fmt.Printf(" Daemonset/%s event: %#v\n", d.ResourceName, e.Type)
}

var object *extensions.DaemonSet
var object *appsv1.DaemonSet

if e.Type != watch.Error {
var ok bool
object, ok = e.Object.(*extensions.DaemonSet)
object, ok = e.Object.(*appsv1.DaemonSet)
if !ok {
return true, fmt.Errorf("expected %s to be a *extensions.DaemonSet, got %T", d.ResourceName, e.Object)
return true, fmt.Errorf("expected %s to be a *appsv1.DaemonSet, got %T", d.ResourceName, e.Object)
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ func (d *Tracker) runPodTracker(podName string) error {
return nil
}

func (d *Tracker) handleDaemonSetStatus(object *extensions.DaemonSet) (ready bool, err error) {
func (d *Tracker) handleDaemonSetStatus(object *appsv1.DaemonSet) (ready bool, err error) {
if debug.Debug() {
fmt.Printf("%s\n", getDaemonSetStatus(object))
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/tracker/deployment/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"
"strings"

extensions "k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"

"k8s.io/client-go/kubernetes"

"github.com/flant/kubedog/pkg/tracker/debug"
"github.com/flant/kubedog/pkg/utils"
)

func getDeploymentStatus(client kubernetes.Interface, prevObj *extensions.Deployment, newObj *extensions.Deployment) string {
func getDeploymentStatus(client kubernetes.Interface, prevObj *appsv1.Deployment, newObj *appsv1.Deployment) string {
if prevObj == nil {
prevObj = newObj
}
Expand All @@ -35,7 +35,7 @@ func getDeploymentStatus(client kubernetes.Interface, prevObj *extensions.Deploy
return strings.Join(msgs, "\n")
}

func getReplicaSetsStatus(client kubernetes.Interface, deployment *extensions.Deployment) string {
func getReplicaSetsStatus(client kubernetes.Interface, deployment *appsv1.Deployment) string {
msgs := []string{}

_, allOlds, newRs, err := utils.GetAllReplicaSets(deployment, client)
Expand Down
10 changes: 5 additions & 5 deletions pkg/tracker/deployment/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/flant/kubedog/pkg/tracker/pod"
"github.com/flant/kubedog/pkg/utils"

extensions "k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
)

type DeploymentStatus struct {
extensions.DeploymentStatus
appsv1.DeploymentStatus

StatusGeneration uint64

Expand All @@ -31,7 +31,7 @@ type DeploymentStatus struct {
NewPodsNames []string
}

func NewDeploymentStatus(object *extensions.Deployment, statusGeneration uint64, isTrackerFailed bool, trackerFailedReason string, podsStatuses map[string]pod.PodStatus, newPodsNames []string) DeploymentStatus {
func NewDeploymentStatus(object *appsv1.Deployment, statusGeneration uint64, isTrackerFailed bool, trackerFailedReason string, podsStatuses map[string]pod.PodStatus, newPodsNames []string) DeploymentStatus {
res := DeploymentStatus{
StatusGeneration: statusGeneration,
DeploymentStatus: object.Status,
Expand Down Expand Up @@ -105,7 +105,7 @@ processingPodsStatuses:
}

// Status returns a message describing deployment status, and a bool value indicating if the status is considered done.
func DeploymentRolloutStatus(deployment *extensions.Deployment, revision int64) (string, bool, error) {
func DeploymentRolloutStatus(deployment *appsv1.Deployment, revision int64) (string, bool, error) {
if revision > 0 {
deploymentRev, err := utils.Revision(deployment)
if err != nil {
Expand All @@ -116,7 +116,7 @@ func DeploymentRolloutStatus(deployment *extensions.Deployment, revision int64)
}
}
if deployment.Generation <= deployment.Status.ObservedGeneration {
cond := utils.GetDeploymentCondition(deployment.Status, extensions.DeploymentProgressing)
cond := utils.GetDeploymentCondition(deployment.Status, appsv1.DeploymentProgressing)
if cond != nil && cond.Reason == utils.TimedOutReason {
return "", false, fmt.Errorf("deployment %q exceeded its progress deadline", deployment.Name)
}
Expand Down
46 changes: 23 additions & 23 deletions pkg/tracker/deployment/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
watchtools "k8s.io/client-go/tools/watch"
)
Expand All @@ -29,12 +29,12 @@ type Tracker struct {

State string
Conditions []string
FinalDeploymentStatus extensions.DeploymentStatus
FinalDeploymentStatus appsv1.DeploymentStatus
NewReplicaSetName string
CurrentReady bool

knownReplicaSets map[string]*extensions.ReplicaSet
lastObject *extensions.Deployment
knownReplicaSets map[string]*appsv1.ReplicaSet
lastObject *appsv1.Deployment
statusGeneration uint64
failedReason string
podStatuses map[string]pod.PodStatus
Expand All @@ -50,13 +50,13 @@ type Tracker struct {
PodError chan replicaset.ReplicaSetPodError
StatusReport chan DeploymentStatus

resourceAdded chan *extensions.Deployment
resourceModified chan *extensions.Deployment
resourceDeleted chan *extensions.Deployment
resourceAdded chan *appsv1.Deployment
resourceModified chan *appsv1.Deployment
resourceDeleted chan *appsv1.Deployment
resourceFailed chan string
replicaSetAdded chan *extensions.ReplicaSet
replicaSetModified chan *extensions.ReplicaSet
replicaSetDeleted chan *extensions.ReplicaSet
replicaSetAdded chan *appsv1.ReplicaSet
replicaSetModified chan *appsv1.ReplicaSet
replicaSetDeleted chan *appsv1.ReplicaSet
podAdded chan *corev1.Pod
podDone chan string
errors chan error
Expand Down Expand Up @@ -93,20 +93,20 @@ func NewTracker(ctx context.Context, name, namespace string, kube kubernetes.Int
StatusReport: make(chan DeploymentStatus, 100),
//PodReady: make(chan bool, 1),

knownReplicaSets: make(map[string]*extensions.ReplicaSet),
knownReplicaSets: make(map[string]*appsv1.ReplicaSet),
podStatuses: make(map[string]pod.PodStatus),
rsNameByPod: make(map[string]string),

TrackedPods: make([]string, 0),

//PodError: make(chan PodError, 0),
resourceAdded: make(chan *extensions.Deployment, 1),
resourceModified: make(chan *extensions.Deployment, 1),
resourceDeleted: make(chan *extensions.Deployment, 1),
resourceAdded: make(chan *appsv1.Deployment, 1),
resourceModified: make(chan *appsv1.Deployment, 1),
resourceDeleted: make(chan *appsv1.Deployment, 1),
resourceFailed: make(chan string, 1),
replicaSetAdded: make(chan *extensions.ReplicaSet, 1),
replicaSetModified: make(chan *extensions.ReplicaSet, 1),
replicaSetDeleted: make(chan *extensions.ReplicaSet, 1),
replicaSetAdded: make(chan *appsv1.ReplicaSet, 1),
replicaSetModified: make(chan *appsv1.ReplicaSet, 1),
replicaSetDeleted: make(chan *appsv1.ReplicaSet, 1),
podAdded: make(chan *corev1.Pod, 1),
podDone: make(chan string, 1),
errors: make(chan error, 0),
Expand Down Expand Up @@ -317,24 +317,24 @@ func (d *Tracker) runDeploymentInformer() {
}
lw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return client.ExtensionsV1beta1().Deployments(d.Namespace).List(tweakListOptions(options))
return client.AppsV1().Deployments(d.Namespace).List(tweakListOptions(options))
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return client.ExtensionsV1beta1().Deployments(d.Namespace).Watch(tweakListOptions(options))
return client.AppsV1().Deployments(d.Namespace).Watch(tweakListOptions(options))
},
}

go func() {
_, err := watchtools.UntilWithSync(d.Context, lw, &extensions.Deployment{}, nil, func(e watch.Event) (bool, error) {
_, err := watchtools.UntilWithSync(d.Context, lw, &appsv1.Deployment{}, nil, func(e watch.Event) (bool, error) {
if debug.Debug() {
fmt.Printf(" deploy/%s event: %#v\n", d.ResourceName, e.Type)
}

var object *extensions.Deployment
var object *appsv1.Deployment

if e.Type != watch.Error {
var ok bool
object, ok = e.Object.(*extensions.Deployment)
object, ok = e.Object.(*appsv1.Deployment)
if !ok {
return true, fmt.Errorf("expected %s to be a *extension.Deployment, got %T", d.ResourceName, e.Object)
}
Expand Down Expand Up @@ -473,7 +473,7 @@ func (d *Tracker) runPodTracker(podName, rsName string) error {
return nil
}

func (d *Tracker) handleDeploymentState(object *extensions.Deployment) (ready bool, err error) {
func (d *Tracker) handleDeploymentState(object *appsv1.Deployment) (ready bool, err error) {
if debug.Debug() {
fmt.Printf("%s\n%s\n",
getDeploymentStatus(d.Kube, d.lastObject, object),
Expand Down
Loading

0 comments on commit 0c24f4c

Please sign in to comment.