Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Jun 27, 2019
1 parent 30e329d commit 2970ee2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 68 deletions.
61 changes: 0 additions & 61 deletions pkg/await/fixtures/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package fixtures

import (
appsv1 "k8s.io/api/apps/v1"
appsv1beta1 "k8s.io/api/apps/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -71,63 +70,3 @@ func DeploymentBasic() *deploymentBasic {
},
}
}

type deploymentOld struct {
Object *appsv1beta1.Deployment
Unstructured *unstructured.Unstructured
}

func DeploymentOld() *deploymentOld {
return &deploymentOld{
&appsv1beta1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1beta1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Spec: appsv1beta1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "foo",
Image: "nginx",
},
},
},
},
},
},

&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo"},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
"app": "nginx",
},
},
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"name": "foo",
"image": "nginx"}},
},
},
},
},
},
}
}
28 changes: 28 additions & 0 deletions pkg/await/fixtures/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ func PodReady(name, namespace string) *corev1.Pod {
return pod
}

func PodSucceeded(name, namespace string) *corev1.Pod {
pod := PodBase(name, namespace)
pod.Spec.RestartPolicy = corev1.RestartPolicyNever
pod.Status = corev1.PodStatus{
Phase: corev1.PodSucceeded,
Conditions: []corev1.PodCondition{
{
Type: corev1.PodInitialized,
Status: corev1.ConditionTrue,
},
{
Type: corev1.PodReady,
Status: corev1.ConditionFalse,
},
{
Type: corev1.ContainersReady,
Status: corev1.ConditionFalse,
},
{
Type: corev1.PodScheduled,
Status: corev1.ConditionTrue,
},
},
}

return pod
}

func PodScheduled(name, namespace string) *corev1.Pod {
pod := PodBase(name, namespace)
pod.Status = corev1.PodStatus{
Expand Down
17 changes: 11 additions & 6 deletions pkg/await/states/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func Test_podInitialized(t *testing.T) {
want bool
}{
{
"true",
"Pod initialized",
args{fixtures.PodInitialized("foo", "bar")},
true,
},
{
"false",
"Pod uninitialized",
args{fixtures.PodUninitialized("foo", "bar")},
false,
},
Expand All @@ -76,12 +76,17 @@ func Test_podReady(t *testing.T) {
want bool
}{
{
"true",
"Pod ready",
args{fixtures.PodReady("foo", "bar")},
true,
},
{
"false",
"Pod succeeded",
args{fixtures.PodSucceeded("foo", "bar")},
true,
},
{
"Pod unready",
args{fixtures.PodBase("foo", "bar")},
false,
},
Expand All @@ -105,12 +110,12 @@ func Test_podScheduled(t *testing.T) {
want bool
}{
{
"true",
"Pod scheduled",
args{fixtures.PodScheduled("foo", "bar")},
true,
},
{
"false",
"Pod unscheduled",
args{fixtures.PodUnscheduled("foo", "bar")},
false,
},
Expand Down
9 changes: 8 additions & 1 deletion pkg/logging/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,30 @@ func (m Message) String() string {
return m.S
}

// Empty returns true if the Message is uninitialized, false otherwise.
func (m Message) Empty() bool {
return len(m.S) == 0 && len(m.Severity) == 0
}

// StatusMessage creates a Message with Severity set to Info.
func StatusMessage(msg string) Message {
return Message{S: msg, Severity: diag.Info}
}

// WarningMessage creates a Message with Severity set to Warning.
func WarningMessage(msg string) Message {
return Message{S: msg, Severity: diag.Warning}
}

// ErrorMessage creates a Message with Severity set to Error.
func ErrorMessage(msg string) Message {
return Message{S: msg, Severity: diag.Error}
}

// Messages is a slice of Message types.
type Messages []Message

// Infos returns Messages with Info severity.
func (m Messages) Infos() Messages {
var messages Messages
for _, message := range m {
Expand All @@ -57,6 +63,7 @@ func (m Messages) Infos() Messages {
return messages
}

// Warnings returns Messages with Warning severity.
func (m Messages) Warnings() Messages {
var messages Messages
for _, message := range m {
Expand All @@ -68,6 +75,7 @@ func (m Messages) Warnings() Messages {
return messages
}

// Errors returns Messages with Error severity.
func (m Messages) Errors() Messages {
var messages Messages
for _, message := range m {
Expand All @@ -78,4 +86,3 @@ func (m Messages) Errors() Messages {

return messages
}

0 comments on commit 2970ee2

Please sign in to comment.