Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 39 additions & 1 deletion pkg/cmd/kubectl/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ package kubectl

import (
"fmt"
"strings"
"text/tabwriter"
"github.com/spf13/cobra"

kctl "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/client"
)

func DescriberFor(kind string, c *client.Client) (kctl.Describer, bool) {
func DescriberFor(kind string, c *client.Client, cmd *cobra.Command) (kctl.Describer, bool) {
switch kind {
case "Build":
return &BuildDescriber{
BuildClient: func(namespace string) (client.BuildInterface, error) {
return c.Builds(namespace), nil
},
}, true
case "BuildConfig":
return &BuildConfigDescriber{
BuildConfigClient: func(namespace string) (client.BuildConfigInterface, error) {
return c.BuildConfigs(namespace), nil
},
Command: cmd,
}, true
case "Deployment":
return &DeploymentDescriber{
DeploymentClient: func(namespace string) (client.DeploymentInterface, error) {
Expand Down Expand Up @@ -88,6 +98,34 @@ func (d *BuildDescriber) Describe(namespace, name string) (string, error) {
})
}

// BuildConfigDescriber generates information about a buildConfig
type BuildConfigDescriber struct {
BuildConfigClient func(namespace string) (client.BuildConfigInterface, error)
Command *cobra.Command
}

func (d *BuildConfigDescriber) Describe(namespace, name string) (string, error) {
bc, err := d.BuildConfigClient(namespace)
if err != nil {
return "", err
}
buildConfig, err := bc.Get(name)
if err != nil {
return "", err
}
webhooks := WebhookUrl(buildConfig, kubecmd.GetKubeConfig(d.Command))
buildDescriber := &BuildDescriber{}

return tabbedString(func(out *tabwriter.Writer) error {
formatMeta(out, buildConfig.ObjectMeta)
buildDescriber.DescribeParameters(buildConfig.Parameters, out)
for whType, whURL := range webhooks {
fmt.Fprintf(out, "Webhook %s:\t%s\n", strings.Title(string(whType)), string(whURL))
}
return nil
})
}

// DeploymentDescriber generates information about a deployment
type DeploymentDescriber struct {
DeploymentClient func(namespace string) (client.DeploymentInterface, error)
Expand Down
26 changes: 26 additions & 0 deletions pkg/cmd/kubectl/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"fmt"
"text/tabwriter"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/api/latest"
)

func tabbedString(f func(*tabwriter.Writer) error) (string, error) {
Expand Down Expand Up @@ -39,3 +43,25 @@ func formatMeta(out *tabwriter.Writer, m api.ObjectMeta) {
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(m.Labels))
fmt.Fprintf(out, "Created:\t%s\n", m.CreationTimestamp)
}


// WebhookUrl assembles map with of webhook type as key and webhook url and value
func WebhookUrl(bc *buildapi.BuildConfig, config *kclient.Config) map[string]string {
triggers := make(map[string]string)
for i, trigger := range bc.Triggers {
var whTrigger string
switch trigger.Type {
case "github":
whTrigger = trigger.GithubWebHook.Secret
case "generic":
whTrigger = trigger.GenericWebHook.Secret
}
apiVersion := latest.Version
if accessor, err := meta.Accessor(bc); err == nil && len(accessor.APIVersion()) > 0 {
apiVersion = accessor.APIVersion()
}
url := fmt.Sprintf("%s/osapi/%s/buildConfigHooks/%s/%s/%s", config.Host, apiVersion, bc.Name, whTrigger, bc.Triggers[i].Type)
triggers[string(trigger.Type)] = url
}
return triggers
}
2 changes: 1 addition & 1 deletion pkg/cmd/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ https://github.com/openshift/origin.`,
// Initialize describer for Origin objects
factory.OriginDescriber = func(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.Describer, error) {
if c, err := factory.OriginClient(cmd, mapping); err == nil {
if describer, ok := DescriberFor(mapping.Kind, c); ok == true {
if describer, ok := DescriberFor(mapping.Kind, c, cmd); ok == true {
return describer, nil
}
}
Expand Down