-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: calvin0327 <[email protected]>
- Loading branch information
calvin0327
committed
Sep 11, 2022
1 parent
ba14329
commit 9116dc5
Showing
5 changed files
with
240 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,28 @@ | ||
/* | ||
Copyright 2021 clusterpedia Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
clusterpediaclient "github.com/clusterpedia-io/client-go/clusterpediaclient" | ||
"github.com/clusterpedia-io/client-go/tools/builder" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
"github.com/clusterpedia-io/client-go/client" | ||
) | ||
|
||
func main() { | ||
restConfig, err := ctrl.GetConfig() | ||
config, err := ctrl.GetConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
cc, err := clusterpediaclient.NewForConfig(restConfig) | ||
client, err := client.NewClusterForConfig(config, "cluster1") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
collectionResource, err := cc.PediaClusterV1beta1().CollectionResource().List(context.TODO(), metav1.ListOptions{}) | ||
pod, err := client.CoreV1().Pods("default").Get(context.TODO(), "pod1", metav1.GetOptions{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, item := range collectionResource.Items { | ||
fmt.Printf("resource info: %v\n", item) | ||
} | ||
|
||
// build listOptions | ||
options := builder.ListOptionsBuilder(). | ||
Namespaces("kube-system"). | ||
Options() | ||
|
||
resources, err := cc.PediaClusterV1beta1().CollectionResource().Fetch(context.TODO(), "workflows", options, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, item := range resources.Items { | ||
fmt.Printf("resource info: %v\n", item) | ||
} | ||
fmt.Println(pod) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2021 clusterpedia Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
clusterpediaclient "github.com/clusterpedia-io/client-go/clusterpediaclient" | ||
"github.com/clusterpedia-io/client-go/tools/builder" | ||
) | ||
|
||
func main() { | ||
restConfig, err := ctrl.GetConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
cc, err := clusterpediaclient.NewForConfig(restConfig) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
collectionResource, err := cc.PediaClusterV1beta1().CollectionResource().List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, item := range collectionResource.Items { | ||
fmt.Printf("resource info: %v\n", item) | ||
} | ||
|
||
// build listOptions | ||
options := builder.ListOptionsBuilder(). | ||
Namespaces("kube-system"). | ||
Options() | ||
|
||
resources, err := cc.PediaClusterV1beta1().CollectionResource().Fetch(context.TODO(), "workflows", options, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, item := range resources.Items { | ||
fmt.Printf("resource info: %v\n", item) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/clusterpedia-io/client-go/tools/transport" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
clientset "k8s.io/client-go/kubernetes" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func main() { | ||
config, err := ctrl.GetConfig() | ||
if err != nil { | ||
log.Fatalf("failed to init config: %v", err) | ||
} | ||
config.Wrap(func(rt http.RoundTripper) http.RoundTripper { | ||
return transport.NewTransportForCluster(config.Host, "cluster", rt) | ||
}) | ||
|
||
client, err := clientset.NewForConfig(config) | ||
if err != nil { | ||
log.Fatalf("failed to init clientset: %v", err) | ||
} | ||
|
||
pod, err := client.CoreV1().Pods("demo-system").Get(context.TODO(), "pod1", metav1.GetOptions{}) | ||
if err != nil { | ||
log.Fatalf("failed to list pods: %v", err) | ||
} | ||
fmt.Println(pod) | ||
} |
Oops, something went wrong.