mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-22 01:17:16 +00:00
* feat: added prehook for creating ns * feat: added prehook for creating ns Initial Draft * feat: added prehook for creating ns * feat: added prehook for creating ns * feat: added prehook for creating ns checking the health of namespace created. * feat: added prehook for creating ns. checking if ns existed already. * feat: getSyncTasks returns the same list each time. added checking if resources contains ns already. * feat: move const variable to right location; added additional checking if namespace is included in resources. * feat: fixing compile issue. * feat: moved code closer together. * feat: adding test cases. * feat: auto create only for sc.namespace * feat: fix failed test * feat: update livObj * feat: added error handling * feat: added error handling * feat: move into its own fuction * feat: fixing compile error
99 lines
1.7 KiB
Go
99 lines
1.7 KiB
Go
package testing
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
)
|
|
|
|
const (
|
|
FakeArgoCDNamespace = "fake-argocd-ns"
|
|
)
|
|
|
|
func HelmHook(obj *unstructured.Unstructured, hookType string) *unstructured.Unstructured {
|
|
return Annotate(obj, "helm.sh/hook", hookType)
|
|
}
|
|
|
|
func Annotate(obj *unstructured.Unstructured, key, val string) *unstructured.Unstructured {
|
|
annotations := obj.GetAnnotations()
|
|
if annotations == nil {
|
|
annotations = map[string]string{}
|
|
}
|
|
annotations[key] = val
|
|
obj.SetAnnotations(annotations)
|
|
return obj
|
|
}
|
|
|
|
var PodManifest = `
|
|
{
|
|
"apiVersion": "v1",
|
|
"kind": "Pod",
|
|
"metadata": {
|
|
"name": "my-pod"
|
|
},
|
|
"spec": {
|
|
"containers": [
|
|
{
|
|
"image": "nginx:1.7.9",
|
|
"name": "nginx",
|
|
"resources": {
|
|
"requests": {
|
|
"cpu": 0.2
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
`
|
|
|
|
func NewPod() *unstructured.Unstructured {
|
|
return Unstructured(PodManifest)
|
|
}
|
|
|
|
var ServiceManifest = `
|
|
{
|
|
"apiVersion": "v1",
|
|
"kind": "Service",
|
|
"metadata": {
|
|
"name": "my-service"
|
|
},
|
|
"spec": {
|
|
"ports": [
|
|
{
|
|
"name": "http",
|
|
"protocol": "TCP",
|
|
"port": 80,
|
|
"targetPort": 8080
|
|
}
|
|
],
|
|
"selector": {
|
|
"app": "my-service"
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
func NewService() *unstructured.Unstructured {
|
|
return Unstructured(ServiceManifest)
|
|
}
|
|
|
|
func NewCRD() *unstructured.Unstructured {
|
|
return Unstructured(`apiVersion: apiextensions.k8s.io/v1beta1
|
|
kind: CustomResourceDefinition
|
|
metadata:
|
|
name: testcrds.argoproj.io
|
|
spec:
|
|
group: argoproj.io
|
|
version: v1
|
|
scope: Namespaced
|
|
names:
|
|
plural: testcrds
|
|
kind: TestCrd`)
|
|
}
|
|
|
|
func NewNamespace() *unstructured.Unstructured {
|
|
return Unstructured(`apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: testnamespace
|
|
spec:`)
|
|
}
|