Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Get individual namespaces when given whitelist #1298

Merged
merged 3 commits into from
Aug 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type Cluster struct {
version string // string response for the version command.
logger log.Logger
sshKeyRing ssh.KeyRing
nsWhitelist map[string]bool
nsWhitelist []string

mu sync.Mutex
}
Expand All @@ -114,11 +114,6 @@ func NewCluster(clientset k8sclient.Interface,
logger log.Logger,
nsWhitelist []string) *Cluster {

nsWhitelistMap := map[string]bool{}
for _, namespace := range nsWhitelist {
nsWhitelistMap[namespace] = true
}

c := &Cluster{
client: extendedClient{
clientset,
Expand All @@ -127,7 +122,7 @@ func NewCluster(clientset k8sclient.Interface,
applier: applier,
logger: logger,
sshKeyRing: sshKeyRing,
nsWhitelist: nsWhitelistMap,
nsWhitelist: nsWhitelist,
}

return c
Expand Down Expand Up @@ -315,20 +310,21 @@ func (c *Cluster) PublicSSHKey(regenerate bool) (ssh.PublicKey, error) {
// instance, in which case it returns a list containing the namespaces from the whitelist
// that exist in the cluster.
func (c *Cluster) getAllowedNamespaces() ([]apiv1.Namespace, error) {
nsList := []apiv1.Namespace{}
if len(c.nsWhitelist) > 0 {
nsList := []apiv1.Namespace{}
for _, name := range c.nsWhitelist {
if ns, err := c.client.CoreV1().Namespaces().Get(name, meta_v1.GetOptions{}); err == nil {
nsList = append(nsList, *ns)
} else if !(apierrors.IsNotFound(err) || apierrors.IsUnauthorized(err) || apierrors.IsForbidden(err)) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

return nil, err
}
}
return nsList, nil
}

namespaces, err := c.client.CoreV1().Namespaces().List(meta_v1.ListOptions{})
if err != nil {
return nsList, err
return nil, err
}

for _, namespace := range namespaces.Items {
if len(c.nsWhitelist) > 0 && !c.nsWhitelist[namespace.ObjectMeta.Name] {
continue
}

nsList = append(nsList, namespace)
}

return nsList, nil
return namespaces.Items, nil
}