Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyingjunz committed Dec 3, 2023
1 parent 0a85813 commit d50b442
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
25 changes: 4 additions & 21 deletions practise/k8s-practise/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -21,28 +20,12 @@ func main() {
panic(err)
}

name := "nginx"
namespace := "default"
deployment, err := clientSet.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{})
obj, err := clientSet.CoreV1().Nodes().Get(context.TODO(), "kirin", metav1.GetOptions{})
if err != nil {
panic(err)
}

fieldSelector := []string{
"involvedObject.uid=" + string(deployment.UID),
"involvedObject.name=" + deployment.Name,
"involvedObject.namespace=" + deployment.Namespace,
"involvedObject.kind=Deployment",
}

events, err := clientSet.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{
FieldSelector: strings.Join(fieldSelector, ","),
Limit: 500,
})
if err != nil {
panic(err)
}

fmt.Println("events.Items", events.Items)
fmt.Println("events.Items", len(events.Items))
obj.Annotations["testkey"] = "testvalue"
_, _ = clientSet.CoreV1().Nodes().Update(context.TODO(), obj, metav1.UpdateOptions{})
fmt.Println(obj.Annotations)
}
26 changes: 0 additions & 26 deletions t1.go

This file was deleted.

0 comments on commit d50b442

Please sign in to comment.