File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright 2019 The Kubernetes Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'kubernetes'
16
+ require 'pp'
17
+
18
+ config = Kubernetes ::Configuration . default_config ( )
19
+ client = Kubernetes ::ApiClient . new ( config )
20
+
21
+ watch = Kubernetes ::Watch . new ( client )
22
+
23
+ watch . connect ( '/api/v1/namespaces' ) do |obj |
24
+ pp obj
25
+ end
Original file line number Diff line number Diff line change 16
16
require 'kubernetes/version'
17
17
require 'kubernetes/configuration'
18
18
require 'kubernetes/loader'
19
+ require 'kubernetes/watch'
19
20
20
21
# Configuration
21
22
require 'kubernetes/config/error'
Original file line number Diff line number Diff line change
1
+ # Copyright 2019 The Kubernetes Authors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'json'
16
+
17
+ # The Kubernetes module encapsulates the Kubernetes client for Ruby
18
+ module Kubernetes
19
+ class Watch
20
+ def initialize ( client )
21
+ @client = client
22
+ end
23
+
24
+ def connect ( path , &block )
25
+ opts = {
26
+ :auth_names => [ 'BearerToken' ]
27
+ }
28
+ request = @client . build_request ( 'GET' , path + '?watch=true' , opts )
29
+ request . on_body do |chunk |
30
+ parts = chunk . split ( /\n / )
31
+ parts . each do |part |
32
+ obj = JSON . parse ( part )
33
+ yield obj
34
+ end
35
+ end
36
+ response = request . run
37
+
38
+ pp response
39
+ end
40
+ end
41
+ end
You can’t perform that action at this time.
0 commit comments