commit
03c43b611c
3 changed files with 95 additions and 3 deletions
|
@ -128,10 +128,20 @@ func NewIngressController(backend ingress.Controller) *GenericController {
|
|||
glog.Infof("service %v validated as source of Ingress status", *publishSvc)
|
||||
}
|
||||
|
||||
if *configMap != "" {
|
||||
_, _, err = k8s.ParseNameNS(*configMap)
|
||||
for _, configMap := range []string{*configMap, *tcpConfigMapName, *udpConfigMapName} {
|
||||
_, err = k8s.IsValidConfigMap(kubeClient, configMap)
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("configmap error: %v", err)
|
||||
glog.Fatalf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if *watchNamespace != "" {
|
||||
|
||||
_, err = k8s.IsValidNamespace(kubeClient, *watchNamespace)
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("no watchNamespace with name %v found: %v", *watchNamespace, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,30 @@ func IsValidService(kubeClient clientset.Interface, name string) (*api.Service,
|
|||
return kubeClient.Core().Services(ns).Get(name)
|
||||
}
|
||||
|
||||
// isValidConfigMap check if exists a configmap with the specified name
|
||||
func IsValidConfigMap(kubeClient clientset.Interface, fullName string) (*api.ConfigMap, error) {
|
||||
|
||||
ns, name, err := ParseNameNS(fullName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configMap, err := kubeClient.Core().ConfigMaps(ns).Get(name)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("configmap not found: %v", err)
|
||||
}
|
||||
|
||||
return configMap, nil
|
||||
|
||||
}
|
||||
|
||||
// isValidNamespace chck if exists a namespace with the specified name
|
||||
func IsValidNamespace(kubeClient clientset.Interface, name string) (*api.Namespace, error) {
|
||||
return kubeClient.Core().Namespaces().Get(name)
|
||||
}
|
||||
|
||||
// IsValidSecret checks if exists a secret with the specified name
|
||||
func IsValidSecret(kubeClient clientset.Interface, name string) (*api.Secret, error) {
|
||||
ns, name, err := ParseNameNS(name)
|
||||
|
|
|
@ -85,6 +85,64 @@ func TestIsValidService(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIsValidNamespace(t *testing.T) {
|
||||
|
||||
fk := testclient.NewSimpleClientset(&api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "default",
|
||||
},
|
||||
})
|
||||
|
||||
_, err := IsValidNamespace(fk, "empty")
|
||||
if err == nil {
|
||||
t.Errorf("expected error but return nill")
|
||||
}
|
||||
|
||||
ns, err := IsValidNamespace(fk, "default")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if ns == nil {
|
||||
t.Errorf("expected a configmap but returned nil")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIsValidConfigMap(t *testing.T) {
|
||||
|
||||
fk := testclient.NewSimpleClientset(&api.ConfigMap{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Namespace: api.NamespaceDefault,
|
||||
Name: "demo",
|
||||
},
|
||||
})
|
||||
|
||||
_, err := IsValidConfigMap(fk, "")
|
||||
if err == nil {
|
||||
t.Errorf("expected error but return nill")
|
||||
}
|
||||
|
||||
s, err := IsValidConfigMap(fk, "default/demo")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
t.Errorf("expected a configmap but returned nil")
|
||||
}
|
||||
|
||||
fk = testclient.NewSimpleClientset()
|
||||
s, err = IsValidConfigMap(fk, "default/demo")
|
||||
if err == nil {
|
||||
t.Errorf("expected an error but returned nil")
|
||||
}
|
||||
if s != nil {
|
||||
t.Errorf("unexpected Configmap returned: %v", s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIsValidSecret(t *testing.T) {
|
||||
fk := testclient.NewSimpleClientset(&api.Secret{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
|
Loading…
Reference in a new issue