Skip to content

Commit

Permalink
Merge pull request #16652 from mfojtik/sts-get-pod
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 16347, 16652).

cli: add statefulsets to PodForResource

Fixes: #16650

@smarterclayton PTAL
  • Loading branch information
openshift-merge-robot committed Oct 3, 2017
2 parents 813f39e + 2ee28ae commit 7585e7e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
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

0 comments on commit 7585e7e

Please sign in to comment.