-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support new event version #171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
const ( | ||
EventVersionOld = "corev1" | ||
EventVersionNew = "eventsv1" | ||
) | ||
|
||
var cluster string | ||
var EventVersion string | ||
|
||
func SetClusterName(client *kubernetes.Clientset) { | ||
setCluster(client) | ||
t := time.NewTicker(60 * time.Second) | ||
defer t.Stop() | ||
for { | ||
select { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 成功一次还需要继续 loop 吗 会有 cluster 改名的情况吗,很少吧 |
||
case <-t.C: | ||
if cluster != "" { | ||
return | ||
} | ||
setCluster(client) | ||
klog.Infof("current cluster is [%s]", GetCluster()) | ||
} | ||
} | ||
|
||
} | ||
|
||
func setCluster(client *kubernetes.Clientset) { | ||
|
||
ns, err := client.CoreV1().Namespaces().Get(context.Background(), "kubesphere-system", metav1.GetOptions{}) | ||
if err != nil { | ||
klog.Errorf("get namespace kubesphere-system error: %s", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function needs to exit here, otherwise, ns will be nil and the following code will report an error. |
||
return | ||
} | ||
|
||
if ns.Annotations != nil { | ||
cluster = ns.Annotations["cluster.kubesphere.io/name"] | ||
} | ||
|
||
} | ||
|
||
func GetCluster() string { | ||
return cluster | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports not sort