Browse code

oc: enable autoscale for dcs

Michail Kargakis authored on 2016/01/28 07:24:32
Showing 8 changed files
... ...
@@ -5823,6 +5823,104 @@ _oc_convert()
5823 5823
     must_have_one_noun=()
5824 5824
 }
5825 5825
 
5826
+_oc_autoscale()
5827
+{
5828
+    last_command="oc_autoscale"
5829
+    commands=()
5830
+
5831
+    flags=()
5832
+    two_word_flags=()
5833
+    flags_with_completion=()
5834
+    flags_completion=()
5835
+
5836
+    flags+=("--cpu-percent=")
5837
+    flags+=("--dry-run")
5838
+    flags+=("--filename=")
5839
+    flags_with_completion+=("--filename")
5840
+    flags_completion+=("__handle_filename_extension_flag json|yaml|yml")
5841
+    two_word_flags+=("-f")
5842
+    flags_with_completion+=("-f")
5843
+    flags_completion+=("__handle_filename_extension_flag json|yaml|yml")
5844
+    flags+=("--generator=")
5845
+    flags+=("--max=")
5846
+    flags+=("--min=")
5847
+    flags+=("--name=")
5848
+    flags+=("--no-headers")
5849
+    flags+=("--output=")
5850
+    two_word_flags+=("-o")
5851
+    flags+=("--output-version=")
5852
+    flags+=("--save-config")
5853
+    flags+=("--show-all")
5854
+    flags+=("-a")
5855
+    flags+=("--sort-by=")
5856
+    flags+=("--template=")
5857
+    two_word_flags+=("-t")
5858
+    flags+=("--alsologtostderr")
5859
+    flags+=("--api-version=")
5860
+    flags+=("--boot-id-file=")
5861
+    flags+=("--certificate-authority=")
5862
+    flags_with_completion+=("--certificate-authority")
5863
+    flags_completion+=("_filedir")
5864
+    flags+=("--client-certificate=")
5865
+    flags_with_completion+=("--client-certificate")
5866
+    flags_completion+=("_filedir")
5867
+    flags+=("--client-key=")
5868
+    flags_with_completion+=("--client-key")
5869
+    flags_completion+=("_filedir")
5870
+    flags+=("--cluster=")
5871
+    flags+=("--config=")
5872
+    flags_with_completion+=("--config")
5873
+    flags_completion+=("_filedir")
5874
+    flags+=("--container-hints=")
5875
+    flags+=("--context=")
5876
+    flags+=("--docker=")
5877
+    flags+=("--docker-only")
5878
+    flags+=("--docker-root=")
5879
+    flags+=("--docker-run=")
5880
+    flags+=("--enable-load-reader")
5881
+    flags+=("--event-storage-age-limit=")
5882
+    flags+=("--event-storage-event-limit=")
5883
+    flags+=("--global-housekeeping-interval=")
5884
+    flags+=("--google-json-key=")
5885
+    flags+=("--housekeeping-interval=")
5886
+    flags+=("--httptest.serve=")
5887
+    flags+=("--insecure-skip-tls-verify")
5888
+    flags+=("--ir-data-source=")
5889
+    flags+=("--ir-dbname=")
5890
+    flags+=("--ir-influxdb-host=")
5891
+    flags+=("--ir-namespace-only")
5892
+    flags+=("--ir-password=")
5893
+    flags+=("--ir-percentile=")
5894
+    flags+=("--ir-user=")
5895
+    flags+=("--log-backtrace-at=")
5896
+    flags+=("--log-cadvisor-usage")
5897
+    flags+=("--log-dir=")
5898
+    flags+=("--log-flush-frequency=")
5899
+    flags+=("--logtostderr")
5900
+    flags+=("--machine-id-file=")
5901
+    flags+=("--match-server-version")
5902
+    flags+=("--namespace=")
5903
+    two_word_flags+=("-n")
5904
+    flags+=("--nosystemd")
5905
+    flags+=("--server=")
5906
+    flags+=("--stderrthreshold=")
5907
+    flags+=("--storage-driver-buffer-duration=")
5908
+    flags+=("--storage-driver-db=")
5909
+    flags+=("--storage-driver-host=")
5910
+    flags+=("--storage-driver-password=")
5911
+    flags+=("--storage-driver-secure")
5912
+    flags+=("--storage-driver-table=")
5913
+    flags+=("--storage-driver-user=")
5914
+    flags+=("--token=")
5915
+    flags+=("--user=")
5916
+    flags+=("--v=")
5917
+    flags+=("--vmodule=")
5918
+
5919
+    must_have_one_flag=()
5920
+    must_have_one_flag+=("--max=")
5921
+    must_have_one_noun=()
5922
+}
5923
+
5826 5924
 _oc_logout()
5827 5925
 {
5828 5926
     last_command="oc_logout"
... ...
@@ -6968,6 +7066,7 @@ _oc()
6968 6968
     commands+=("policy")
6969 6969
     commands+=("secrets")
6970 6970
     commands+=("convert")
6971
+    commands+=("autoscale")
6971 6972
     commands+=("logout")
6972 6973
     commands+=("config")
6973 6974
     commands+=("whoami")
... ...
@@ -11594,6 +11594,104 @@ _openshift_cli_convert()
11594 11594
     must_have_one_noun=()
11595 11595
 }
11596 11596
 
11597
+_openshift_cli_autoscale()
11598
+{
11599
+    last_command="openshift_cli_autoscale"
11600
+    commands=()
11601
+
11602
+    flags=()
11603
+    two_word_flags=()
11604
+    flags_with_completion=()
11605
+    flags_completion=()
11606
+
11607
+    flags+=("--cpu-percent=")
11608
+    flags+=("--dry-run")
11609
+    flags+=("--filename=")
11610
+    flags_with_completion+=("--filename")
11611
+    flags_completion+=("__handle_filename_extension_flag json|yaml|yml")
11612
+    two_word_flags+=("-f")
11613
+    flags_with_completion+=("-f")
11614
+    flags_completion+=("__handle_filename_extension_flag json|yaml|yml")
11615
+    flags+=("--generator=")
11616
+    flags+=("--max=")
11617
+    flags+=("--min=")
11618
+    flags+=("--name=")
11619
+    flags+=("--no-headers")
11620
+    flags+=("--output=")
11621
+    two_word_flags+=("-o")
11622
+    flags+=("--output-version=")
11623
+    flags+=("--save-config")
11624
+    flags+=("--show-all")
11625
+    flags+=("-a")
11626
+    flags+=("--sort-by=")
11627
+    flags+=("--template=")
11628
+    two_word_flags+=("-t")
11629
+    flags+=("--alsologtostderr")
11630
+    flags+=("--api-version=")
11631
+    flags+=("--boot-id-file=")
11632
+    flags+=("--certificate-authority=")
11633
+    flags_with_completion+=("--certificate-authority")
11634
+    flags_completion+=("_filedir")
11635
+    flags+=("--client-certificate=")
11636
+    flags_with_completion+=("--client-certificate")
11637
+    flags_completion+=("_filedir")
11638
+    flags+=("--client-key=")
11639
+    flags_with_completion+=("--client-key")
11640
+    flags_completion+=("_filedir")
11641
+    flags+=("--cluster=")
11642
+    flags+=("--config=")
11643
+    flags_with_completion+=("--config")
11644
+    flags_completion+=("_filedir")
11645
+    flags+=("--container-hints=")
11646
+    flags+=("--context=")
11647
+    flags+=("--docker=")
11648
+    flags+=("--docker-only")
11649
+    flags+=("--docker-root=")
11650
+    flags+=("--docker-run=")
11651
+    flags+=("--enable-load-reader")
11652
+    flags+=("--event-storage-age-limit=")
11653
+    flags+=("--event-storage-event-limit=")
11654
+    flags+=("--global-housekeeping-interval=")
11655
+    flags+=("--google-json-key=")
11656
+    flags+=("--housekeeping-interval=")
11657
+    flags+=("--httptest.serve=")
11658
+    flags+=("--insecure-skip-tls-verify")
11659
+    flags+=("--ir-data-source=")
11660
+    flags+=("--ir-dbname=")
11661
+    flags+=("--ir-influxdb-host=")
11662
+    flags+=("--ir-namespace-only")
11663
+    flags+=("--ir-password=")
11664
+    flags+=("--ir-percentile=")
11665
+    flags+=("--ir-user=")
11666
+    flags+=("--log-backtrace-at=")
11667
+    flags+=("--log-cadvisor-usage")
11668
+    flags+=("--log-dir=")
11669
+    flags+=("--log-flush-frequency=")
11670
+    flags+=("--logtostderr")
11671
+    flags+=("--machine-id-file=")
11672
+    flags+=("--match-server-version")
11673
+    flags+=("--namespace=")
11674
+    two_word_flags+=("-n")
11675
+    flags+=("--nosystemd")
11676
+    flags+=("--server=")
11677
+    flags+=("--stderrthreshold=")
11678
+    flags+=("--storage-driver-buffer-duration=")
11679
+    flags+=("--storage-driver-db=")
11680
+    flags+=("--storage-driver-host=")
11681
+    flags+=("--storage-driver-password=")
11682
+    flags+=("--storage-driver-secure")
11683
+    flags+=("--storage-driver-table=")
11684
+    flags+=("--storage-driver-user=")
11685
+    flags+=("--token=")
11686
+    flags+=("--user=")
11687
+    flags+=("--v=")
11688
+    flags+=("--vmodule=")
11689
+
11690
+    must_have_one_flag=()
11691
+    must_have_one_flag+=("--max=")
11692
+    must_have_one_noun=()
11693
+}
11694
+
11597 11695
 _openshift_cli_logout()
11598 11696
 {
11599 11697
     last_command="openshift_cli_logout"
... ...
@@ -12739,6 +12837,7 @@ _openshift_cli()
12739 12739
     commands+=("policy")
12740 12740
     commands+=("secrets")
12741 12741
     commands+=("convert")
12742
+    commands+=("autoscale")
12742 12743
     commands+=("logout")
12743 12744
     commands+=("config")
12744 12745
     commands+=("whoami")
... ...
@@ -68,6 +68,22 @@ Attach to a running container.
68 68
 ====
69 69
 
70 70
 
71
+== oc autoscale
72
+Autoscale a deployment config or replication controller
73
+
74
+====
75
+
76
+[options="nowrap"]
77
+----
78
+  # Auto scale a deployment config "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies:
79
+  $ oc autoscale dc/foo --min=2 --max=10
80
+
81
+  # Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%
82
+  $ oc autoscale rc/foo --max=5 --cpu-percent=80
83
+----
84
+====
85
+
86
+
71 87
 == oc cancel-build
72 88
 Cancel a pending or running build
73 89
 
... ...
@@ -131,6 +131,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
131 131
 				policy.NewCmdPolicy(policy.PolicyRecommendedName, fullName+" "+policy.PolicyRecommendedName, f, out),
132 132
 				secrets.NewCmdSecrets(secrets.SecretsRecommendedName, fullName+" "+secrets.SecretsRecommendedName, f, in, out, fullName+" edit"),
133 133
 				cmd.NewCmdConvert(fullName, f, out),
134
+				cmd.NewCmdAutoscale(fullName, f, out),
134 135
 			},
135 136
 		},
136 137
 		{
... ...
@@ -273,6 +273,29 @@ func NewCmdScale(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Co
273 273
 }
274 274
 
275 275
 const (
276
+	autoScaleLong = `Autoscale a deployment config or replication controller.
277
+
278
+Looks up a deployment config or replication controller by name and creates an autoscaler that uses
279
+this deployment config or replication controller as a reference. An autoscaler can automatically
280
+increase or decrease number of pods deployed within the system as needed.`
281
+
282
+	autoScaleExample = `  # Auto scale a deployment config "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies:
283
+  $ %[1]s autoscale dc/foo --min=2 --max=10
284
+
285
+  # Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%%
286
+  $ %[1]s autoscale rc/foo --max=5 --cpu-percent=80`
287
+)
288
+
289
+// NewCmdAutoscale is a wrapper for the Kubernetes cli autoscale command
290
+func NewCmdAutoscale(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
291
+	cmd := kcmd.NewCmdAutoscale(f.Factory, out)
292
+	cmd.Short = "Autoscale a deployment config or replication controller"
293
+	cmd.Long = autoScaleLong
294
+	cmd.Example = fmt.Sprintf(autoScaleExample, fullName)
295
+	return cmd
296
+}
297
+
298
+const (
276 299
 	runLong = `Create and run a particular image, possibly replicated
277 300
 
278 301
 Creates a deployment config to manage the created container(s). You can choose to run in the
... ...
@@ -19,7 +19,6 @@ import (
19 19
 var MissingCommands = sets.NewString(
20 20
 	"namespace", "rolling-update",
21 21
 	"cluster-info", "api-versions",
22
-	"autoscale", // TODO
23 22
 	"stop",
24 23
 	"cordon",
25 24
 	"drain",
... ...
@@ -355,6 +355,13 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
355 355
 		}
356 356
 		return kCanBeExposed(kind)
357 357
 	}
358
+	kCanBeAutoscaled := w.Factory.CanBeAutoscaled
359
+	w.CanBeAutoscaled = func(kind unversioned.GroupKind) error {
360
+		if kind == deployapi.Kind("DeploymentConfig") {
361
+			return nil
362
+		}
363
+		return kCanBeAutoscaled(kind)
364
+	}
358 365
 	kAttachablePodForObjectFunc := w.Factory.AttachablePodForObject
359 366
 	w.AttachablePodForObject = func(object runtime.Object) (*api.Pod, error) {
360 367
 		oc, kc, err := w.Clients()
... ...
@@ -97,3 +97,11 @@ os::cmd::expect_success 'oc delete dc/database'
97 97
 os::cmd::expect_failure 'oc get dc/database'
98 98
 os::cmd::expect_failure 'oc get rc/database-1'
99 99
 echo "stop: ok"
100
+
101
+os::cmd::expect_success 'oc create -f test/integration/fixtures/test-deployment-config.yaml'
102
+os::cmd::expect_success 'oc autoscale dc/test-deployment-config --max 5'
103
+os::cmd::expect_success_and_text "oc get hpa/test-deployment-config --template='{{.spec.maxReplicas}}'" "5"
104
+os::cmd::expect_success 'oc delete dc/test-deployment-config'
105
+os::cmd::expect_success 'oc delete hpa/test-deployment-config'
106
+echo "autoscale: ok"
107
+