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

cli: add statefulsets to PodForResource #16652

Merged
merged 2 commits into from
Oct 3, 2017
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
19 changes: 19 additions & 0 deletions pkg/cmd/util/clientcmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/pkg/apis/apps"
kclientcmd "k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
Expand Down Expand Up @@ -313,6 +314,24 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
return "", err
}
return pod.Name, nil
case apps.Resource("statefulsets"):
kc, err := f.ClientSet()
if err != nil {
return "", err
}
s, err := kc.Apps().StatefulSets(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return "", err
}
selector, err := metav1.LabelSelectorAsSelector(s.Spec.Selector)
if err != nil {
return "", err
}
pod, _, err := kcmdutil.GetFirstPod(kc.Core(), namespace, selector, timeout, sortBy)
if err != nil {
return "", err
}
return pod.Name, nil
case extensions.Resource("replicasets"):
kc, err := f.ClientSet()
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions test/end-to-end/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ os::cmd::expect_success_and_text "oc exec ${frontend_pod} id" '1000'
os::cmd::expect_success_and_text "oc rsh pod/${frontend_pod} id -u" '1000'
os::cmd::expect_success_and_text "oc rsh -T ${frontend_pod} id -u" '1000'

os::log::info "Check we can get access to statefulset container via rsh"
os::cmd::expect_success_and_text "oc create -f test/testdata/statefulset.yaml" 'statefulset "testapp" created'
os::cmd::try_until_text "oc get pod testapp-0 -o jsonpath='{.status.phase}'" "Running" "$(( 2*TIME_MIN ))"
os::cmd::expect_success_and_text "oc rsh sts/testapp echo 1" "1"
os::cmd::expect_success_and_text "oc delete sts/testapp" 'statefulset "testapp" deleted'

# test that rsh inherits the TERM variable by default
# this must be done as an echo and not an argument to rsh because rsh only sets the TERM if
# no arguments are supplied.
Expand Down
18 changes: 18 additions & 0 deletions test/testdata/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: testapp
spec:
replicas: 1
template:
metadata:
labels:
app: testapp
spec:
containers:
- name: testapp
image: centos/ruby-22-centos7:latest
command:
- /bin/sleep
args:
- infinity