Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting GetLabelValues & DeleteProject function to client-go #448

Merged
merged 1 commit into from
May 18, 2018
Merged
Changes from all commits
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: 6 additions & 28 deletions pkg/occlient/occlient.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,7 @@ func (c *Client) Delete(kind string, name string, labels map[string]string) (str
}

func (c *Client) DeleteProject(name string) error {
_, err := c.runOcComamnd(&OcCommand{
args: []string{"delete", "project", name},
})
err := c.projectClient.Projects().Delete(name, &metav1.DeleteOptions{})
if err != nil {
return errors.Wrap(err, "unable to delete project")
}
Expand All @@ -1098,38 +1096,18 @@ func (c *Client) DeleteProject(name string) error {
// GetLabelValues get label values of given label from objects in project that are matching selector
// returns slice of uniq label values
func (c *Client) GetLabelValues(project string, label string, selector string) ([]string, error) {
// get all object that have given label
// and show just label values separated by ,
args := []string{
"get", "all",
"--selector", selector,
"--namespace", project,
"-o", "go-template={{range .items}}{{range $key, $value := .metadata.labels}}{{if eq $key \"" + label + "\"}}{{$value}},{{end}}{{end}}{{end}}",
}

output, err := c.runOcComamnd(&OcCommand{args: args})
dcList, err := c.appsClient.DeploymentConfigs(project).List(metav1.ListOptions{LabelSelector: selector})
if err != nil {
return nil, err
return nil, errors.Wrap(err, "unable to list DeploymentConfigs")
}

var values []string
// deduplicate label values
for _, val := range strings.Split(string(output), ",") {
val = strings.TrimSpace(val)
if val != "" {
// check if this is the first time we see this value
found := false
for _, existing := range values {
if val == existing {
found = true
}
}
if !found {
for _, elem := range dcList.Items {
for key, val := range elem.Labels {
if key == label {
values = append(values, val)
}
}
}

return values, nil
}

Expand Down