Skip to content

Commit

Permalink
Fix activation creation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RemindD committed Jun 11, 2024
1 parent ade2d89 commit c67236a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 16 deletions.
51 changes: 35 additions & 16 deletions api/pkg/apis/v1alpha1/vendors/stage-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,29 @@ func (s *StageVendor) Init(config vendors.VendorConfig, factories []managers.IMa
return v1alpha2.NewCOAError(nil, "event body is not an activation job", v1alpha2.BadRequest)
}
campaignName := api_utils.ReplaceSeperator(actData.Campaign)

campaign, err := s.CampaignsManager.GetState(context.TODO(), campaignName, actData.Namespace)
if err != nil {
log.Error("V (Stage): unable to find campaign: %+v", err)
err = s.reportActivationStatusWithBadRequest(actData.Activation, actData.Namespace, err)
// If report status succeeded, return an empty err so the subscribe function will not be retried
// The actual error will be stored in Activation cr
return err
}
activation, err := s.ActivationsManager.GetState(context.TODO(), actData.Activation, actData.Namespace)
if err != nil {
log.Error("V (Stage): unable to find activation: %+v", err)
err = s.reportActivationStatusWithBadRequest(actData.Activation, actData.Namespace, err)
// If report status succeeded, return an empty err so the subscribe function will not be retried
// The actual error will be stored in Activation cr
return err
}

evt, err := s.StageManager.HandleActivationEvent(context.TODO(), actData, *campaign.Spec, activation)
if err != nil {
err = s.reportActivationStatusWithBadRequest(actData.Activation, actData.Namespace, err)
// If report status succeeded, return an empty err so the subscribe function will not be retried
// The actual error will be stored in Activation cr
return err
}

Expand All @@ -122,30 +132,22 @@ func (s *StageVendor) Init(config vendors.VendorConfig, factories []managers.IMa
err := json.Unmarshal(jData, &triggerData)
if err != nil {
err = v1alpha2.NewCOAError(nil, "event body is not an activation job", v1alpha2.BadRequest)
status.Status = v1alpha2.BadRequest
status.StatusMessage = v1alpha2.BadRequest.String()
status.ErrorMessage = err.Error()
status.IsActive = false
sLog.Errorf("V (Stage): failed to deserialize activation data: %v", err)
err = s.ActivationsManager.ReportStatus(context.TODO(), triggerData.Activation, triggerData.Namespace, status)
if err != nil {
sLog.Errorf("V (Stage): failed to report error status: %v (%v)", status.ErrorMessage, err)
}
err = s.reportActivationStatusWithBadRequest(triggerData.Activation, triggerData.Namespace, err)
// If report status succeeded, return an empty err so the subscribe function will not be retried
// The actual error will be stored in Activation cr
return err
}
status.Outputs["__namespace"] = triggerData.Namespace

campaignName := api_utils.ReplaceSeperator(triggerData.Campaign)
campaign, err := s.CampaignsManager.GetState(context.TODO(), campaignName, triggerData.Namespace)
if err != nil {
status.Status = v1alpha2.BadRequest
status.StatusMessage = v1alpha2.BadRequest.String()
status.ErrorMessage = err.Error()
status.IsActive = false
sLog.Errorf("V (Stage): failed to get campaign spec: %v", err)
err = s.ActivationsManager.ReportStatus(context.TODO(), triggerData.Activation, triggerData.Namespace, status)
if err != nil {
sLog.Errorf("V (Stage): failed to report error status: %v (%v)", status.ErrorMessage, err)
}
err = s.reportActivationStatusWithBadRequest(triggerData.Activation, triggerData.Namespace, err)
// If report status succeeded, return an empty err so the subscribe function will not be retried
// The actual error will be stored in Activation cr
return err
}
status.Stage = triggerData.Stage
status.ActivationGeneration = triggerData.ActivationGeneration
Expand Down Expand Up @@ -306,3 +308,20 @@ func (s *StageVendor) Init(config vendors.VendorConfig, factories []managers.IMa
})
return nil
}

func (s *StageVendor) reportActivationStatusWithBadRequest(activation string, namespace string, err error) error {
status := model.ActivationStatus{
Stage: "",
NextStage: "",
Outputs: map[string]interface{}{},
Status: v1alpha2.BadRequest,
StatusMessage: v1alpha2.BadRequest.String(),
ErrorMessage: err.Error(),
IsActive: true,
}
err = s.ActivationsManager.ReportStatus(context.TODO(), activation, namespace, status)
if err != nil {
sLog.Errorf("V (Stage): failed to report error status on activtion %s/%s: %v (%v)", namespace, activation, status.ErrorMessage, err)
}
return err
}
40 changes: 40 additions & 0 deletions k8s/config/oss/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ webhooks:
resources:
- solutions
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-workflow-symphony-v1-activation
failurePolicy: Fail
name: mactivation.kb.io
rules:
- apiGroups:
- workflow.symphony
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- activations
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -150,6 +170,26 @@ webhooks:
resources:
- solutions
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-workflow-symphony-v1-activation
failurePolicy: Fail
name: mactivation.kb.io
rules:
- apiGroups:
- workflow.symphony
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- activations
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
4 changes: 4 additions & 0 deletions k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Skill")
os.Exit(1)
}
if err = (&workflowv1.Activation{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Skill")
os.Exit(1)
}
if err = (&federationv1.Catalog{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Catalog")
os.Exit(1)
Expand Down
40 changes: 40 additions & 0 deletions packages/helm/symphony/templates/symphony-core/symphonyk8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,26 @@ webhooks:
resources:
- solutions
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: '{{ include "symphony.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /mutate-workflow-symphony-v1-activation
failurePolicy: Fail
name: mactivation.kb.io
rules:
- apiGroups:
- workflow.symphony
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- activations
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -2794,6 +2814,26 @@ webhooks:
resources:
- solutions
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: '{{ include "symphony.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /validate-workflow-symphony-v1-activation
failurePolicy: Fail
name: mactivation.kb.io
rules:
- apiGroups:
- workflow.symphony
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- activations
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down

0 comments on commit c67236a

Please sign in to comment.