diff --git a/pkg/cmd/kubectl/describer.go b/pkg/cmd/kubectl/describer.go index 4147d505a462..c647e2ffd5e3 100644 --- a/pkg/cmd/kubectl/describer.go +++ b/pkg/cmd/kubectl/describer.go @@ -2,14 +2,17 @@ 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{ @@ -17,6 +20,13 @@ func DescriberFor(kind string, c *client.Client) (kctl.Describer, bool) { 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) { @@ -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) diff --git a/pkg/cmd/kubectl/helpers.go b/pkg/cmd/kubectl/helpers.go index 7727f004bffa..1213f764975d 100644 --- a/pkg/cmd/kubectl/helpers.go +++ b/pkg/cmd/kubectl/helpers.go @@ -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) { @@ -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 +} \ No newline at end of file diff --git a/pkg/cmd/kubectl/kubectl.go b/pkg/cmd/kubectl/kubectl.go index 82f49084b361..5d254b28abe0 100644 --- a/pkg/cmd/kubectl/kubectl.go +++ b/pkg/cmd/kubectl/kubectl.go @@ -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 } }