-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(namespaces): Add namespaces response
- Loading branch information
Zachary Seguin
committed
Aug 13, 2020
1 parent
42c7019
commit 4370e46
Showing
5 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"sort" | ||
|
||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
type namespacesresponse struct { | ||
APIResponse | ||
Namespaces []string `json:"namespaces"` | ||
} | ||
|
||
// GetNamespaces returns the namespaces in the environment. | ||
func (s *server) GetNamespaces(w http.ResponseWriter, r *http.Request) { | ||
log.Printf("loading namespaces") | ||
|
||
namespaces, err := s.listers.namespaces.List(labels.Everything()) | ||
if err != nil { | ||
s.error(w, r, err) | ||
return | ||
} | ||
|
||
sort.Sort(namespacesByName(namespaces)) | ||
|
||
resp := namespacesresponse{ | ||
APIResponse: APIResponse{ | ||
Success: true, | ||
}, | ||
Namespaces: make([]string, 0), | ||
} | ||
|
||
for _, namespace := range namespaces { | ||
resp.Namespaces = append(resp.Namespaces, namespace.Name) | ||
} | ||
|
||
s.respond(w, r, resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters