argo-cd/test/testdata.go

97 lines
1.9 KiB
Go

package test
import (
"github.com/gobuffalo/packr"
appsv1 "k8s.io/api/apps/v1"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/errors"
)
const (
TestNamespace = "test-namespace"
TestAppInstanceName = "test-app-instance"
)
var (
box = packr.NewBox("../util/rbac")
BuiltinPolicy string
)
func init() {
var err error
BuiltinPolicy, err = box.MustString("builtin-policy.csv")
errors.CheckError(err)
}
func DemoService() *apiv1.Service {
return &apiv1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
Namespace: TestNamespace,
Labels: map[string]string{
common.LabelKeyAppInstance: TestAppInstanceName,
},
},
Spec: apiv1.ServiceSpec{
Ports: []apiv1.ServicePort{
{
Port: 80,
TargetPort: intstr.FromInt(80),
},
},
Selector: map[string]string{
"app": "demo",
},
Type: "ClusterIP",
},
}
}
func DemoDeployment() *appsv1.Deployment {
var two int32 = 2
return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1beta1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "demo",
Namespace: TestNamespace,
Labels: map[string]string{
common.LabelKeyAppInstance: TestAppInstanceName,
},
},
Spec: appsv1.DeploymentSpec{
Replicas: &two,
Template: apiv1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "demo",
},
},
Spec: apiv1.PodSpec{
Containers: []apiv1.Container{
{
Name: "demo",
Image: "gcr.io/kuar-demo/kuard-amd64:1",
Ports: []apiv1.ContainerPort{
{
ContainerPort: 80,
},
},
},
},
},
},
},
}
}