Skip to content

Commit 9f0a206

Browse files
authored
Merge pull request #23757 from dougsland/docs-doug
[docs] fix client-go example
2 parents ef7b80d + a4fc1d7 commit 9f0a206

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

content/en/docs/tasks/administer-cluster/access-cluster-api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ The Go client can use the same [kubeconfig file](/docs/concepts/configuration/or
171171
as the kubectl CLI does to locate and authenticate to the API server. See this [example](https://git.k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go):
172172

173173
```golang
174+
package main
175+
174176
import (
177+
"context"
175178
"fmt"
176179
"k8s.io/apimachinery/pkg/apis/meta/v1"
177180
"k8s.io/client-go/kubernetes"
@@ -185,7 +188,7 @@ func main() {
185188
// creates the clientset
186189
clientset, _ := kubernetes.NewForConfig(config)
187190
// access the API to list pods
188-
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{})
191+
pods, _ := clientset.CoreV1().Pods("").List(context.TODO(), v1.ListOptions{})
189192
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
190193
}
191194
```

content/ko/docs/tasks/administer-cluster/access-cluster-api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ Go 클라이언트는 kubectl CLI가 API 서버를 찾아 인증하기 위해
171171
사용할 수 있다. 이 [예제](https://git.k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go)를 참고한다.
172172

173173
```golang
174+
package main
175+
174176
import (
177+
"context"
175178
"fmt"
176179
"k8s.io/apimachinery/pkg/apis/meta/v1"
177180
"k8s.io/client-go/kubernetes"
@@ -185,7 +188,7 @@ func main() {
185188
// clientset을 생성한다
186189
clientset, _ := kubernetes.NewForConfig(config)
187190
// 파드를 나열하기 위해 API에 접근한다
188-
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{})
191+
pods, _ := clientset.CoreV1().Pods("").List(context.TODO(), v1.ListOptions{})
189192
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
190193
}
191194
```

content/zh/docs/tasks/administer-cluster/access-cluster-api.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,14 @@ Go 客户端可以使用与 kubectl 命令行工具相同的
277277
[例子](https://git.k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go)
278278

279279
```golang
280+
package main
281+
280282
import (
283+
"context"
281284
"fmt"
282-
"k8s.io/client-go/1.4/kubernetes"
283-
"k8s.io/client-go/1.4/pkg/api/v1"
284-
"k8s.io/client-go/1.4/tools/clientcmd"
285+
"k8s.io/apimachinery/pkg/apis/meta/v1"
286+
"k8s.io/client-go/kubernetes"
287+
"k8s.io/client-go/tools/clientcmd"
285288
)
286289

287290
func main() {
@@ -291,7 +294,7 @@ func main() {
291294
// creates the clientset
292295
clientset, _ := kubernetes.NewForConfig(config)
293296
// access the API to list pods
294-
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{})
297+
pods, _ := clientset.CoreV1().Pods("").List(context.TODO(), v1.ListOptions{})
295298
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
296299
}
297300
```

0 commit comments

Comments
 (0)