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

WIP: kubectl support for origin resources #1

Open
wants to merge 24 commits into
base: osc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e1b205
WIP: introducing osc
fabianofranz Sep 18, 2014
4f0b3e8
WIP: introducing osc
fabianofranz Sep 19, 2014
4c5cc4a
WIP - getting rid of base/base.go
fabianofranz Sep 22, 2014
bce54f1
WIP - removed colors for now, printer interface
fabianofranz Sep 22, 2014
45cd962
WIP - NewCommandDeployment installs all, inline version cmd, osc root…
fabianofranz Sep 29, 2014
27d5f30
WIP - printer can't be global
fabianofranz Sep 29, 2014
c758534
WIP
fabianofranz Sep 29, 2014
74b755d
WIP
fabianofranz Sep 30, 2014
4aa669e
WIP: added config skeleton and client for commands
fabianofranz Sep 30, 2014
4d640e4
WIP - minor adjustments
fabianofranz Oct 1, 2014
f58667c
WIP - pods
fabianofranz Oct 1, 2014
235dc17
WIP
fabianofranz Oct 2, 2014
37f399f
WIP login|logout
fabianofranz Oct 10, 2014
788a09a
WIP - rebase to latest origin, exposing kube apply as osc create for now
fabianofranz Oct 29, 2014
b3fb2b2
Temporarily vendoring kubectl in origin/pkg/kubectl
fabianofranz Oct 31, 2014
2fdcb2c
Exposes 'openshift kubectl'
fabianofranz Oct 31, 2014
da1819a
Vendoring missing kubectl dependencies
fabianofranz Oct 31, 2014
9530862
osc create|get|describe|update|delete through kubectl subcommands
fabianofranz Oct 31, 2014
afd2a8d
Port kubectl namespace support
derekwaynecarr Nov 4, 2014
e3ea96a
Update api2 internal references to api2, and client2 to client2
derekwaynecarr Nov 5, 2014
5ab27a0
Register project with api2 scheme for kubectl
derekwaynecarr Nov 5, 2014
b8f07c5
Remove trace
derekwaynecarr Nov 5, 2014
c5e20bc
Map api2 to api on import
derekwaynecarr Nov 5, 2014
b930e95
Fixup client to map api2 to api
derekwaynecarr Nov 5, 2014
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
1 change: 1 addition & 0 deletions cmd/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {

openshiftCmd.AddCommand(server.NewCommandStartServer("start"))
openshiftCmd.AddCommand(client.NewCommandKubecfg("kube"))
openshiftCmd.AddCommand(client.NewCommandKubectl("kubectl"))
flagtypes.GLog(openshiftCmd.PersistentFlags())

// version information
Expand Down
3 changes: 3 additions & 0 deletions cmd/osc/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Package main contains the main executable for OpenShift 3 `osc` which is the end-user
// client binary.
package main
90 changes: 90 additions & 0 deletions cmd/osc/osc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"fmt"
"os"

"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/cmd/auth"
"github.com/openshift/origin/pkg/cmd/setup"
kubectl "github.com/openshift/origin/pkg/kubectl/cmd"
"github.com/openshift/origin/pkg/version"
"github.com/spf13/cobra"
)

const longDescription = `
End-user client tool for OpenShift, the hybrid Platform as a Service by the open source leader Red Hat.

Note: This is an alpha release of OpenShift and will change significantly. See

https://github.com/openshift/origin

for the latest information on OpenShift.

`

// TODO: rebase kubectl and refactor to the new commands structures
func main() {
// Root command
oscCmd := NewCmdOpenShiftClient("osc")

// Version
oscCmd.AddCommand(&cobra.Command{
Use: "version",
Short: fmt.Sprintf("Command '%s' (main)", "version"),
Long: fmt.Sprintf("Command '%s' (main)", "version"),
Run: func(c *cobra.Command, args []string) {
fmt.Println("OpenShift", version.Get().String())
},
})

// Root command execution path
if err := oscCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s", err)
os.Exit(1)
}
}

func NewCmdOpenShiftClient(name string) *cobra.Command {
// Main command
cmd := &cobra.Command{
Use: name,
Short: "Client tools for OpenShift",
Long: longDescription,
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}

// Subcommands
//cmd.AddCommand(create.NewCmdCreate("create"))
//cmd.AddCommand(deployment.NewCmdDeployment("deployment"))
//cmd.AddCommand(pod.NewCmdPod("pod"))
cmd.AddCommand(setup.NewCmdSetup("setup"))
cmd.AddCommand(auth.NewCmdLogin("login"))
cmd.AddCommand(auth.NewCmdLogout("logout"))

// Exposes kubectl subcommands
cmd.PersistentFlags().StringP("server", "s", "", "Kubernetes apiserver to connect to")
cmd.PersistentFlags().StringP("auth-path", "a", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file. If missing, prompt the user. Only used if using https.")
cmd.PersistentFlags().Bool("match-server-version", false, "Require server version to match client version")
cmd.PersistentFlags().String("api-version", latest.Version, "The version of the API to use against the server (used for viewing resources only)")
cmd.PersistentFlags().String("certificate-authority", "", "Path to a certificate file for the certificate authority")
cmd.PersistentFlags().String("client-certificate", "", "Path to a client certificate for TLS.")
cmd.PersistentFlags().String("client-key", "", "Path to a client key file for TLS.")
cmd.PersistentFlags().Bool("insecure-skip-tls-verify", false, "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.")
cmd.PersistentFlags().String("ns-path", os.Getenv("HOME")+"/.kubernetes_ns", "Path to the namespace info file that holds the namespace context to use for CLI requests.")
cmd.PersistentFlags().StringP("namespace", "n", "", "If present, the namespace scope for this CLI request.")

f := kubectl.NewFactory()
out := os.Stdout
//cmds.AddCommand(NewCmdVersion(out))
//cmds.AddCommand(NewCmdProxy(out))
cmd.AddCommand(f.NewCmdGet(out))
cmd.AddCommand(f.NewCmdDescribe(out))
cmd.AddCommand(f.NewCmdCreate(out))
cmd.AddCommand(f.NewCmdUpdate(out))
cmd.AddCommand(f.NewCmdDelete(out))

return cmd
}
2 changes: 1 addition & 1 deletion hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cd "${OS_REPO_ROOT}"

if [[ $# == 0 ]]; then
# Update $@ with the default list of targets to build.
set -- cmd/openshift cmd/openshift-router
set -- cmd/openshift cmd/openshift-router cmd/osc
fi

binaries=()
Expand Down
18 changes: 18 additions & 0 deletions pkg/api/errors/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package errors provides detailed error types for api field validation.
package errors
145 changes: 145 additions & 0 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package errors

import (
"fmt"
"net/http"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)

// statusError is an error intended for consumption by a REST API server.
type statusError struct {
status api.Status
}

// Error implements the Error interface.
func (e *statusError) Error() string {
return e.status.Message
}

// Status converts this error into an api.Status object.
func (e *statusError) Status() api.Status {
return e.status
}

// FromObject generates an statusError from an api.Status, if that is the type of obj; otherwise,
// returns an error created by fmt.Errorf.
func FromObject(obj runtime.Object) error {
switch t := obj.(type) {
case *api.Status:
return &statusError{*t}
}
return fmt.Errorf("unexpected object: %v", obj)
}

// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
func NewNotFound(kind, name string) error {
return &statusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusNotFound,
Reason: api.StatusReasonNotFound,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
},
Message: fmt.Sprintf("%s %q not found", kind, name),
}}
}

// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
func NewAlreadyExists(kind, name string) error {
return &statusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusConflict,
Reason: api.StatusReasonAlreadyExists,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
},
Message: fmt.Sprintf("%s %q already exists", kind, name),
}}
}

// NewConflict returns an error indicating the item can't be updated as provided.
func NewConflict(kind, name string, err error) error {
return &statusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusConflict,
Reason: api.StatusReasonConflict,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
},
Message: fmt.Sprintf("%s %q cannot be updated: %s", kind, name, err),
}}
}

// NewInvalid returns an error indicating the item is invalid and cannot be processed.
func NewInvalid(kind, name string, errs ValidationErrorList) error {
causes := make([]api.StatusCause, 0, len(errs))
for i := range errs {
if err, ok := errs[i].(ValidationError); ok {
causes = append(causes, api.StatusCause{
Type: api.CauseType(err.Type),
Message: err.Error(),
Field: err.Field,
})
}
}
return &statusError{api.Status{
Status: api.StatusFailure,
Code: 422, // RFC 4918
Reason: api.StatusReasonInvalid,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
Causes: causes,
},
Message: fmt.Sprintf("%s %q is invalid: %s", kind, name, errs.ToError()),
}}
}

// IsNotFound returns true if the specified error was created by NewNotFoundErr.
func IsNotFound(err error) bool {
return reasonForError(err) == api.StatusReasonNotFound
}

// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
func IsAlreadyExists(err error) bool {
return reasonForError(err) == api.StatusReasonAlreadyExists
}

// IsConflict determines if the err is an error which indicates the provided update conflicts.
func IsConflict(err error) bool {
return reasonForError(err) == api.StatusReasonConflict
}

// IsInvalid determines if the err is an error which indicates the provided resource is not valid.
func IsInvalid(err error) bool {
return reasonForError(err) == api.StatusReasonInvalid
}

func reasonForError(err error) api.StatusReason {
switch t := err.(type) {
case *statusError:
return t.status.Reason
}
return api.StatusReasonUnknown
}
Loading