Sending namespace if manifest namespace is empty (#2332)
Signed-off-by: Raj Babu Das <raj.das@mayadata.io>
This commit is contained in:
parent
6486a8a43a
commit
38da86f7ff
|
|
@ -15,6 +15,7 @@ require (
|
|||
github.com/pkg/errors v0.9.1
|
||||
github.com/rs/cors v1.6.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/tidwall/gjson v1.6.0
|
||||
github.com/tidwall/sjson v1.1.1
|
||||
github.com/vektah/gqlparser/v2 v2.0.1
|
||||
go.mongodb.org/mongo-driver v1.3.5
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mutations
|
|||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -19,6 +20,7 @@ import (
|
|||
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/graphql/subscriptions"
|
||||
"github.com/litmuschaos/litmus/litmus-portal/graphql-server/utils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/sjson"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
|
@ -217,11 +219,18 @@ func CreateChaosWorkflow(input *model.ChaosWorkFlowInput, r store.StateData) (*m
|
|||
return nil, err
|
||||
}
|
||||
|
||||
workflowNamespace := gjson.Get(newWorkflowManifest, "metadata.namespace").String()
|
||||
|
||||
if workflowNamespace == "" {
|
||||
workflowNamespace = os.Getenv("AGENT_NAMESPACE")
|
||||
}
|
||||
|
||||
subscriptions.SendRequestToSubscriber(graphql.SubscriberRequests{
|
||||
K8sManifest: newWorkflowManifest,
|
||||
RequestType: "create",
|
||||
ProjectID: input.ProjectID,
|
||||
ClusterID: input.ClusterID,
|
||||
Namespace: workflowNamespace,
|
||||
}, r)
|
||||
|
||||
return &model.ChaosWorkFlowResponse{
|
||||
|
|
@ -273,6 +282,7 @@ func DeleteCluster(cluster_id string, r store.StateData) (string, error) {
|
|||
RequestType: "delete",
|
||||
ProjectID: cluster.ProjectID,
|
||||
ClusterID: cluster_id,
|
||||
Namespace: *cluster.AgentNamespace,
|
||||
}, r)
|
||||
}
|
||||
|
||||
|
|
@ -307,11 +317,18 @@ func UpdateWorkflow(workflow *model.ChaosWorkFlowInput, r store.StateData) (*mod
|
|||
return nil, err
|
||||
}
|
||||
|
||||
workflowNamespace := gjson.Get(workflow.WorkflowManifest, "metadata.namespace").String()
|
||||
|
||||
if workflowNamespace == "" {
|
||||
workflowNamespace = os.Getenv("AGENT_NAMESPACE")
|
||||
}
|
||||
|
||||
subscriptions.SendRequestToSubscriber(graphql.SubscriberRequests{
|
||||
K8sManifest: newWorkflowManifest,
|
||||
RequestType: "update",
|
||||
ProjectID: workflow.ProjectID,
|
||||
ClusterID: workflow.ClusterID,
|
||||
Namespace: workflowNamespace,
|
||||
}, r)
|
||||
|
||||
return &model.ChaosWorkFlowResponse{
|
||||
|
|
@ -339,11 +356,18 @@ func DeleteWorkflow(workflow_id string, r store.StateData) (bool, error) {
|
|||
}
|
||||
|
||||
for _, workflow := range workflows {
|
||||
workflowNamespace := gjson.Get(workflow.WorkflowManifest, "metadata.namespace").String()
|
||||
|
||||
if workflowNamespace == "" {
|
||||
workflowNamespace = os.Getenv("AGENT_NAMESPACE")
|
||||
}
|
||||
|
||||
subscriptions.SendRequestToSubscriber(graphql.SubscriberRequests{
|
||||
K8sManifest: workflow.WorkflowManifest,
|
||||
RequestType: "delete",
|
||||
ProjectID: workflow.ProjectID,
|
||||
ClusterID: workflow.ClusterID,
|
||||
Namespace: workflowNamespace,
|
||||
}, r)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ func SendWorkflowEvent(wfRun model.WorkflowRun, r store.StateData) {
|
|||
}
|
||||
|
||||
func SendRequestToSubscriber(subscriberRequest graphql.SubscriberRequests, r store.StateData) {
|
||||
namespace := os.Getenv("AGENT_NAMESPACE")
|
||||
if os.Getenv("AGENT_SCOPE") == "cluster" {
|
||||
/*
|
||||
namespace = Obtain from WorkflowManifest or
|
||||
|
|
@ -51,7 +50,7 @@ func SendRequestToSubscriber(subscriberRequest graphql.SubscriberRequests, r sto
|
|||
ProjectID: subscriberRequest.ProjectID,
|
||||
Action: &model.ActionPayload{
|
||||
K8sManifest: subscriberRequest.K8sManifest,
|
||||
Namespace: namespace,
|
||||
Namespace: subscriberRequest.Namespace,
|
||||
RequestType: subscriberRequest.RequestType,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ type SubscriberRequests struct {
|
|||
ExternalData *string `json:"external_data"`
|
||||
ProjectID string `json:"project_id"`
|
||||
ClusterID string `json:"cluster_id"`
|
||||
Namespace string `json:"namespace"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue