Fixing logs of event tracker (#3089)

* Fixing logs of event tracker

Signed-off-by: rajdas98 <mail.rajdas@gmail.com>

* adding AGENT_SCOPE var to check list

Signed-off-by: Raj Babu Das <mail.rajdas@gmail.com>
This commit is contained in:
Raj Babu Das 2021-08-05 20:42:02 +05:30 committed by GitHub
parent ae61c93241
commit e0127c013b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -52,7 +52,7 @@ func init() {
logrus.Info("Go Version: ", rt.Version())
logrus.Info("Go OS/Arch: ", rt.GOOS, "/", rt.GOARCH)
if os.Getenv("IS_CLUSTER_CONFIRMED") == "" || os.Getenv("ACCESS_KEY") == "" || os.Getenv("CLUSTER_ID") == "" || os.Getenv("SERVER_ADDR") == "" || os.Getenv("AGENT_NAMESPACE") == "" {
if os.Getenv("AGENT_SCOPE") == "" || os.Getenv("IS_CLUSTER_CONFIRMED") == "" || os.Getenv("ACCESS_KEY") == "" || os.Getenv("CLUSTER_ID") == "" || os.Getenv("SERVER_ADDR") == "" || os.Getenv("AGENT_NAMESPACE") == "" {
logrus.Fatal("Some environment variable are not setup")
}

View File

@ -49,7 +49,7 @@ func RunDeploymentInformer(factory informers.SharedInformerFactory) {
if depNewObj.GetResourceVersion() != depOldObj.GetResourceVersion() && !reflect.DeepEqual(newDep, oldDep) {
var worflowid = depNewObj.GetAnnotations()["litmuschaos.io/workflow"]
if depNewObj.GetAnnotations()["litmuschaos.io/gitops"] == "true" && worflowid != "" {
log.Print("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "Deployment", depNewObj.Name, depNewObj.Namespace)
log.Printf("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "Deployment", depNewObj.Name, depNewObj.Namespace)
err := PolicyAuditor("Deployment", depNewObj, worflowid)
if err != nil {
log.Print(err)
@ -104,7 +104,7 @@ func RunStsInformer(factory informers.SharedInformerFactory) {
if stsNewObj.GetResourceVersion() != stsOldObj.GetResourceVersion() && !reflect.DeepEqual(newSts, oldSts) {
var worflowid = stsNewObj.GetAnnotations()["litmuschaos.io/workflow"]
if stsNewObj.GetAnnotations()["litmuschaos.io/gitops"] == "true" && worflowid != "" {
log.Print("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "StateFulSet", stsNewObj.Name, stsNewObj.Namespace)
log.Printf("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "StateFulSet", stsNewObj.Name, stsNewObj.Namespace)
err := PolicyAuditor("StateFulSet", stsNewObj, worflowid)
if err != nil {
log.Print(err)
@ -160,7 +160,7 @@ func RunDSInformer(factory informers.SharedInformerFactory) {
if dsNewObj.GetResourceVersion() != dsOldObj.GetResourceVersion() && !reflect.DeepEqual(newDm, oldDm) {
var worflowid = dsNewObj.GetAnnotations()["litmuschaos.io/workflow"]
if dsNewObj.GetAnnotations()["litmuschaos.io/gitops"] == "true" && worflowid != "" {
log.Print("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "DaemonSet", dsNewObj.Name, dsNewObj.Namespace)
log.Printf("EventType: Update \n GitOps Notification for workflowID: %s, ResourceType: %s, ResourceName: %s, ResourceNamespace: %s", worflowid, "DaemonSet", dsNewObj.Name, dsNewObj.Namespace)
err := PolicyAuditor("DaemonSet", dsNewObj, worflowid)
if err != nil {
log.Print(err)

View File

@ -108,6 +108,11 @@ func PolicyAuditor(resourceType string, obj interface{}, workflowid string) erro
return err
}
if len(deploymentConfigList.Items) == 0 {
log.Print("No event-tracker policy(s) found")
return nil
}
for _, ep := range deploymentConfigList.Items {
eventTrackerPolicy, err := clientSet.Resource(deploymentRes).Namespace(AgentNamespace).Get(context.TODO(), ep.GetName(), metav1.GetOptions{})