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

Use a differently-named DC in test/cmd/idle.sh #12590

Merged
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
26 changes: 14 additions & 12 deletions test/cmd/idle.sh
Expand Up @@ -16,21 +16,23 @@ prev_scale_annotation='idling.alpha.openshift.io/previous-scale'
idled_at_template="{{index .metadata.annotations \"${idled_at_annotation}\"}}"
unidle_target_template="{{index .metadata.annotations \"${unidle_target_annotation}\"}}"
prev_scale_template="{{index .metadata.annotations \"${prev_scale_annotation}\"}}"
dc_name=""

setup_idling_resources() {
os::cmd::expect_success 'oc delete all --all'

# set up resources for the idle command
os::cmd::expect_success 'oc create -f test/extended/testdata/idling-echo-server.yaml'
os::cmd::expect_success 'oc describe deploymentconfigs idling-echo'
os::cmd::expect_success 'oc create -f test/testdata/idling-svc-route.yaml'
dc_name=$(basename $(oc create -f test/testdata/idling-dc.yaml -o name)) # `basename type/name` --> name
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not particularly happy with this. In a follow-up we should either:

  • pass it in through a template
  • grab it using jsonpath from the metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-o name is the only supported flag here. We could grab the resource/name with -o name and then extract it using oc get $(resource_with_name) -o go-template=sometemplate or somesuch, but that seems a bit redundant.

Passing it through a template seems like a decent idea, though.

os::cmd::expect_success "oc describe deploymentconfigs '${dc_name}'"
os::cmd::try_until_success 'oc describe endpoints idling-echo'
local endpoints_json
endpoints_json="$(oc get endpoints idling-echo -o json)"
os::cmd::expect_success 'oc delete service idling-echo'
os::cmd::expect_success "echo '${endpoints_json}' | oc create -f -"
os::cmd::expect_success 'oc describe endpoints idling-echo'
# deployer pod won't work, so just scale up the rc ourselves
os::cmd::expect_success 'oc scale replicationcontroller idling-echo-1 --replicas=2'
os::cmd::expect_success "oc scale replicationcontroller ${dc_name}-1 --replicas=2"
os::cmd::try_until_text "oc get pod -l app=idling-echo -o go-template='{{ len .items }}'" "2"
local pod_name
pod_name="$(oc get pod -l app=idling-echo -o go-template='{{ (index .items 0).metadata.name }}')"
Expand All @@ -57,28 +59,28 @@ EOF

os::test::junit::declare_suite_start "cmd/idle/by-name"
setup_idling_resources
os::cmd::expect_failure 'oc idle dc/idling-echo' # make sure manually passing non-endpoints resources fails
os::cmd::expect_success_and_text 'oc idle idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/idling-echo \(unidle to 2 replicas\)"
os::cmd::expect_failure "oc idle dc/${dc_name}" # make sure manually passing non-endpoints resources fails
os::cmd::expect_success_and_text 'oc idle idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/${dc_name} \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${idled_at_template}'" '.'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq 'length == 1 and (.[0] | .replicas == 2 and .name == \"idling-echo\" and .kind == \"DeploymentConfig\")'" 'true'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq '.[] | select(.name == \"${dc_name}\") | (.replicas == 2 and .kind == \"DeploymentConfig\")'" 'true'
os::test::junit::declare_suite_end

os::test::junit::declare_suite_start "cmd/idle/by-label"
setup_idling_resources
os::cmd::expect_success_and_text 'oc idle -l app=idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/idling-echo \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text 'oc idle -l app=idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/${dc_name} \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${idled_at_template}'" '.'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq 'length == 1 and (.[0] | .replicas == 2 and .name == \"idling-echo\" and .kind == \"DeploymentConfig\")'" 'true'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq '.[] | select(.name == \"${dc_name}\") | (.replicas == 2 and .kind == \"DeploymentConfig\")'" 'true'
os::test::junit::declare_suite_end

os::test::junit::declare_suite_start "cmd/idle/all"
setup_idling_resources
os::cmd::expect_success_and_text 'oc idle --all' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/idling-echo \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text 'oc idle --all' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/${dc_name} \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${idled_at_template}'" '.'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq 'length == 1 and (.[0] | .replicas == 2 and .name == \"idling-echo\" and .kind == \"DeploymentConfig\")'" 'true'
os::cmd::expect_success_and_text "oc get endpoints idling-echo -o go-template='${unidle_target_template}' | jq '.[] | select(.name == \"${dc_name}\") | (.replicas == 2 and .kind == \"DeploymentConfig\")'" 'true'
os::test::junit::declare_suite_end

os::test::junit::declare_suite_start "cmd/idle/check-previous-scale"
setup_idling_resources # scales up to 2 replicas
os::cmd::expect_success_and_text 'oc idle idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/idling-echo \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text "oc get dc idling-echo -o go-template='${prev_scale_template}'" '2' # we see the result of the initial scale as the previous scale
os::cmd::expect_success_and_text 'oc idle idling-echo' "Marked service ${project}/idling-echo to unidle resource DeploymentConfig ${project}/${dc_name} \(unidle to 2 replicas\)"
os::cmd::expect_success_and_text "oc get dc ${dc_name} -o go-template='${prev_scale_template}'" '2' # we see the result of the initial scale as the previous scale
os::test::junit::declare_suite_end
39 changes: 39 additions & 0 deletions test/testdata/idling-dc.yaml
@@ -0,0 +1,39 @@
apiVersion: v1
kind: DeploymentConfig
metadata:
generateName: idling-echo-
spec:
replicas: 2
selector:
app: idling-echo
deploymentconfig: idling-echo
strategy:
type: Rolling
template:
metadata:
labels:
app: idling-echo
deploymentconfig: idling-echo
spec:
containers:
- image: openshift/node
name: idling-tcp-echo
command:
- /usr/bin/socat
- TCP4-LISTEN:8675,reuseaddr,fork
- EXEC:'/bin/cat'
ports:
- containerPort: 8675
protocol: TCP
- image: openshift/node
name: idling-udp-echo
command:
- /usr/bin/socat
- UDP4-LISTEN:3090,reuseaddr,fork
- EXEC:'/bin/cat'
ports:
- containerPort: 3090
protocol: UDP
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
62 changes: 62 additions & 0 deletions test/testdata/idling-svc-route.yaml
@@ -0,0 +1,62 @@
apiVersion: v1
kind: List
metadata: {}
items:
- apiVersion: v1
kind: Service
metadata:
name: idling-echo
labels:
app: idling-echo
spec:
selector:
app: idling-echo
ports:
- port: 8675
name: tcp-echo
protocol: TCP
- port: 3090
name: udp-echo
protocol: UDP
- apiVersion: v1
kind: Route
metadata:
name: idling-echo
spec:
to:
kind: Service
name: idling-echo
- apiVersion: v1
kind: Route
metadata:
name: idling-echo-reencrypt
spec:
tls:
termination: reencrypt
# the actual certificate here is not relevant, since we're not
# actually serving TLS
destinationCACertificate: |-
-----BEGIN CERTIFICATE-----
MIIDIjCCAgqgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBoTELMAkGA1UEBhMCVVMx
CzAJBgNVBAgMAlNDMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0Rl
ZmF1bHQgQ29tcGFueSBMdGQxEDAOBgNVBAsMB1Rlc3QgQ0ExGjAYBgNVBAMMEXd3
dy5leGFtcGxlY2EuY29tMSIwIAYJKoZIhvcNAQkBFhNleGF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