runtime/kubernetes: increase debugging (#1841)

This commit is contained in:
ben-toogood 2020-07-15 09:26:25 +01:00 committed by GitHub
parent b27e71ae64
commit f73ec65ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,11 +36,19 @@ type kubernetes struct {
func (k *kubernetes) namespaceExists(name string) (bool, error) { func (k *kubernetes) namespaceExists(name string) (bool, error) {
// populate the cache // populate the cache
if k.namespaces == nil { if k.namespaces == nil {
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("Populating namespace cache")
}
namespaceList := new(client.NamespaceList) namespaceList := new(client.NamespaceList)
resource := &client.Resource{Kind: "namespace", Value: namespaceList} resource := &client.Resource{Kind: "namespace", Value: namespaceList}
if err := k.client.List(resource); err != nil { if err := k.client.List(resource); err != nil {
return false, err return false, err
} }
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
logger.Debugf("Popualted namespace cache successfully with %v items", len(namespaceList.Items))
}
k.namespaces = namespaceList.Items k.namespaces = namespaceList.Items
} }
@ -418,9 +426,15 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er
if namespace != "default" { if namespace != "default" {
if exist, err := k.namespaceExists(namespace); err == nil && !exist { if exist, err := k.namespaceExists(namespace); err == nil && !exist {
if err := k.createNamespace(namespace); err != nil { if err := k.createNamespace(namespace); err != nil {
if logger.V(logger.WarnLevel, logger.DefaultLogger) {
logger.Warnf("Error creating namespacr %v: %v", namespace, err)
}
return err return err
} }
} else if err != nil { } else if err != nil {
if logger.V(logger.WarnLevel, logger.DefaultLogger) {
logger.Warnf("Error checking namespace %v exists: %v", namespace, err)
}
return err return err
} }
} }