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

Cleanup resources after services/guestbook e2e tests. #4492

Merged
merged 2 commits into from
Feb 17, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function kube-up {

local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
local context="${PROJECT}_${INSTANCE_PREFIX}"
local user="${INSTANCE_PREFIX}-admin"
local user="${context}-admin"
local config_dir="${HOME}/.kube/${context}"

# TODO: generate ADMIN (and KUBELET) tokens and put those in the master's
Expand Down
14 changes: 11 additions & 3 deletions docs/kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Additional help topics:
kubectl rollingupdate Perform a rolling update of the given ReplicationController.
kubectl resize Set a new size for a Replication Controller.
kubectl run-container Run a particular image on the cluster.
kubectl stop Gracefully shut down a resource.
kubectl stop Gracefully shut down a resource by id or filename.
kubectl expose Take a replicated application and expose it as Kubernetes Service
kubectl label Update the labels on a resource

Expand Down Expand Up @@ -986,7 +986,7 @@ Global Flags:
```

#### stop
Gracefully shut down a resource.
Gracefully shut down a resource by id or filename.

Attempts to shut down and delete a resource that supports graceful termination.
If the resource is resizable it will be resized to 0 before deletion.
Expand All @@ -996,10 +996,18 @@ Examples:
// Shut down foo.
$ kubectl stop replicationcontroller foo

// Shut down the service defined in service.json
$ kubectl stop -f service.json

// Shut down all resources in the path/to/resources directory
$ kubectl stop -f path/to/resources

Usage:
```
kubectl stop <resource> <id> [flags]
kubectl stop (<resource> <id>|-f filename) [flags]

Flags:
-f, --filename=[]: Filename, directory, or URL to file of resource(s) to be stopped

Global Flags:
--alsologtostderr=false: log to standard error as well as files
Expand Down
7 changes: 3 additions & 4 deletions hack/e2e-suite/guestbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ prepare-e2e

GUESTBOOK="${KUBE_ROOT}/examples/guestbook"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubectl -f can act on entire directories? I had no idea...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. It looks for file extensions that could be schemas and attempts to load them as resources (skipping if invalid schema).


echo "WARNING: this test is a no op that only attempts to launch guestbook resources."
# Launch the guestbook example
${KUBECTL} create -f "${GUESTBOOK}"
${KUBECTL} create -f "${GUESTBOOK}"

sleep 15

Expand All @@ -48,9 +49,7 @@ echo "Pods running: ${POD_LIST_1}"
# TODO make this an actual test. Open up a firewall and use curl to post and
# read a message via the frontend

${KUBECTL} stop rc redis-slave-controller
${KUBECTL} delete services redis-master
${KUBECTL} delete pods redis-master
${KUBECTL} stop -f "${GUESTBOOK}"

POD_LIST_2=$(${KUBECTL} get pods -o template '--template={{range.items}}{{.id}} {{end}}')
echo "Pods running after shutdown: ${POD_LIST_2}"
Expand Down
3 changes: 1 addition & 2 deletions hack/e2e-suite/services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function join() {
svcs_to_clean=()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not affected by your change, but for my own understanding, does anything ever actually get added to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All created services get added to it. See line 74.

function do_teardown() {
local svc
return
for svc in "${svcs_to_clean[@]:+${svcs_to_clean[@]}}"; do
stop_service "${svc}"
done
Expand Down Expand Up @@ -284,7 +283,7 @@ function verify_from_container() {
fi
}

trap "do_teardown" EXIT
trap do_teardown EXIT

# Get node IP addresses and pick one as our test point.
detect-minions
Expand Down
50 changes: 35 additions & 15 deletions pkg/kubectl/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,58 @@ import (
"fmt"
"io"

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/spf13/cobra"
)

func (f *Factory) NewCmdStop(out io.Writer) *cobra.Command {
flags := &struct {
Filenames util.StringList
}{}
cmd := &cobra.Command{
Use: "stop <resource> <id>",
Short: "Gracefully shut down a resource.",
Long: `Gracefully shut down a resource.
Use: "stop (<resource> <id>|-f filename)",
Short: "Gracefully shut down a resource by id or filename.",
Long: `Gracefully shut down a resource by id or filename.

Attempts to shut down and delete a resource that supports graceful termination.
If the resource is resizable it will be resized to 0 before deletion.

Examples:

// Shut down foo.
$ kubectl stop replicationcontroller foo`,
$ kubectl stop replicationcontroller foo

// Shut down the service defined in service.json
$ kubectl stop -f service.json

// Shut down all resources in the path/to/resources directory
$ kubectl stop -f path/to/resources`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
usageError(cmd, "<resource> <id>")
}
cmdNamespace, err := f.DefaultNamespace(cmd)
mapper, _ := f.Object(cmd)
mapping, namespace, name := util.ResourceFromArgs(cmd, args, mapper, cmdNamespace)

reaper, err := f.Reaper(cmd, mapping)
checkErr(err)
mapper, typer := f.Object(cmd)
r := resource.NewBuilder(mapper, typer, f.ClientMapperForCommand(cmd)).
ContinueOnError().
NamespaceParam(cmdNamespace).RequireNamespace().
ResourceTypeOrNameArgs(false, args...).
FilenameParam(flags.Filenames...).
Flatten().
Do()
checkErr(r.Err())

s, err := reaper.Stop(namespace, name)
checkErr(err)
fmt.Fprintf(out, "%s\n", s)
r.Visit(func(info *resource.Info) error {
reaper, err := f.Reaper(cmd, info.Mapping)
checkErr(err)
s, err := reaper.Stop(info.Namespace, info.Name)
if err != nil {
return err
}
fmt.Fprintf(out, "%s\n", s)
return nil
})
},
}
cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file of resource(s) to be stopped")
return cmd
}