mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 03:01:11 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/weaveworks/scope/report"
|
|
|
|
apiv1 "k8s.io/api/core/v1"
|
|
apiv1beta1 "k8s.io/api/extensions/v1beta1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
)
|
|
|
|
// These constants are keys used in node metadata
|
|
const (
|
|
UpdatedReplicas = report.KubernetesUpdatedReplicas
|
|
AvailableReplicas = report.KubernetesAvailableReplicas
|
|
UnavailableReplicas = report.KubernetesUnavailableReplicas
|
|
Strategy = report.KubernetesStrategy
|
|
)
|
|
|
|
// Deployment represents a Kubernetes deployment
|
|
type Deployment interface {
|
|
Meta
|
|
Selector() (labels.Selector, error)
|
|
GetNode(probeID string) report.Node
|
|
}
|
|
|
|
type deployment struct {
|
|
*apiv1beta1.Deployment
|
|
Meta
|
|
Node *apiv1.Node
|
|
}
|
|
|
|
// NewDeployment creates a new Deployment
|
|
func NewDeployment(d *apiv1beta1.Deployment) Deployment {
|
|
return &deployment{Deployment: d, Meta: meta{d.ObjectMeta}}
|
|
}
|
|
|
|
func (d *deployment) Selector() (labels.Selector, error) {
|
|
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return selector, nil
|
|
}
|
|
|
|
func (d *deployment) GetNode(probeID string) report.Node {
|
|
// Spec.Replicas can be omitted, and the pointer will be nil. It defaults to 1.
|
|
desiredReplicas := 1
|
|
if d.Spec.Replicas != nil {
|
|
desiredReplicas = int(*d.Spec.Replicas)
|
|
}
|
|
return d.MetaNode(report.MakeDeploymentNodeID(d.UID())).WithLatests(map[string]string{
|
|
ObservedGeneration: fmt.Sprint(d.Status.ObservedGeneration),
|
|
DesiredReplicas: fmt.Sprint(desiredReplicas),
|
|
Replicas: fmt.Sprint(d.Status.Replicas),
|
|
UpdatedReplicas: fmt.Sprint(d.Status.UpdatedReplicas),
|
|
AvailableReplicas: fmt.Sprint(d.Status.AvailableReplicas),
|
|
UnavailableReplicas: fmt.Sprint(d.Status.UnavailableReplicas),
|
|
Strategy: string(d.Spec.Strategy.Type),
|
|
report.ControlProbeID: probeID,
|
|
NodeType: "Deployment",
|
|
}).WithLatestActiveControls(ScaleUp, ScaleDown)
|
|
}
|