-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support new event version * support new event version
- Loading branch information
1 parent
91e09c2
commit b97c9ce
Showing
5 changed files
with
84 additions
and
14 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
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
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,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 { | ||
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) | ||
return | ||
} | ||
|
||
if ns.Annotations != nil { | ||
cluster = ns.Annotations["cluster.kubesphere.io/name"] | ||
} | ||
|
||
} | ||
|
||
func GetCluster() string { | ||
return cluster | ||
} |