2019-07-02 19:30:42 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 DigitalOcean
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-06-19 18:46:29 +00:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import (
|
2019-06-21 21:36:55 +00:00
|
|
|
"github.com/digitalocean/clusterlint/checks"
|
2019-06-19 18:46:29 +00:00
|
|
|
"github.com/digitalocean/clusterlint/kube"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initPod() *kube.Objects {
|
|
|
|
objs := &kube.Objects{
|
|
|
|
Pods: &corev1.PodList{
|
|
|
|
Items: []corev1.Pod{
|
|
|
|
{
|
2019-06-21 21:36:55 +00:00
|
|
|
TypeMeta: metav1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
2019-06-19 18:46:29 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "pod_foo", Namespace: "k8s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
2019-07-16 18:53:27 +00:00
|
|
|
func initMultiplePods() *kube.Objects {
|
|
|
|
objs := &kube.Objects{
|
|
|
|
Pods: &corev1.PodList{
|
|
|
|
Items: []corev1.Pod{
|
|
|
|
{
|
|
|
|
TypeMeta: metav1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "pod_1", Namespace: "k8s"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TypeMeta: metav1.TypeMeta{Kind: "Pod", APIVersion: "v1"},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "pod_2", Namespace: "k8s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
2019-06-21 21:36:55 +00:00
|
|
|
func GetObjectMeta() *metav1.ObjectMeta {
|
|
|
|
objs := initPod()
|
|
|
|
return &objs.Pods.Items[0].ObjectMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOwners() []metav1.OwnerReference {
|
|
|
|
objs := initPod()
|
|
|
|
return objs.Pods.Items[0].ObjectMeta.GetOwnerReferences()
|
|
|
|
}
|
|
|
|
|
2019-06-19 18:46:29 +00:00
|
|
|
func container(image string) *kube.Objects {
|
|
|
|
objs := initPod()
|
|
|
|
objs.Pods.Items[0].Spec = corev1.PodSpec{
|
|
|
|
Containers: []corev1.Container{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Image: image,
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
|
|
|
func initContainer(image string) *kube.Objects {
|
|
|
|
objs := initPod()
|
|
|
|
objs.Pods.Items[0].Spec = corev1.PodSpec{
|
|
|
|
InitContainers: []corev1.Container{
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Image: image,
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
return objs
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:06:24 +00:00
|
|
|
func issues(severity checks.Severity, message string, kind checks.Kind, check string) []checks.Diagnostic {
|
2019-06-21 21:36:55 +00:00
|
|
|
d := []checks.Diagnostic{
|
|
|
|
{
|
|
|
|
Severity: severity,
|
|
|
|
Message: message,
|
2019-06-25 14:35:34 +00:00
|
|
|
Kind: kind,
|
|
|
|
Object: GetObjectMeta(),
|
2019-06-21 21:36:55 +00:00
|
|
|
Owners: GetOwners(),
|
|
|
|
},
|
2019-06-19 18:46:29 +00:00
|
|
|
}
|
2019-06-21 20:09:43 +00:00
|
|
|
return d
|
2019-06-19 18:46:29 +00:00
|
|
|
}
|