Skip to content

Commit

Permalink
Merge pull request #2061 from opengovern/fix-enable-integration
Browse files Browse the repository at this point in the history
fix: ignore if deployment objects could not be found
  • Loading branch information
artaasadi authored Nov 24, 2024
2 parents 5ac4e8a + 3cb1aa6 commit afcf1a4
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions services/integration/api/integrations/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@ func (h API) EnableIntegrationType(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "current namespace lookup failed")
}

setup, _ := h.database.GetIntegrationTypeSetup(integrationTypeName)
if setup != nil {
if setup.Enabled {
return echo.NewHTTPError(http.StatusBadRequest, "the integration type is already enabled")
}
}

// Scheduled deployment
var describerDeployment appsv1.Deployment
err := h.kubeClient.Get(ctx, client.ObjectKey{
Expand Down Expand Up @@ -1183,6 +1190,11 @@ func (h API) DisableIntegrationType(c echo.Context) error {

integrationTypeName := c.Param("integration_type")

setup, _ := h.database.GetIntegrationTypeSetup(integrationTypeName)
if setup == nil || !setup.Enabled {
return echo.NewHTTPError(http.StatusBadRequest, "the integration type is already disabled")
}

var integrationTypes []integration.Type
integrationTypes = append(integrationTypes, integration.Type(integrationTypeName))

Expand Down Expand Up @@ -1213,12 +1225,12 @@ func (h API) DisableIntegrationType(c echo.Context) error {
}, &describerDeployment)
if err != nil {
h.logger.Error("failed to get manual deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get manual deployment")
}
err = h.kubeClient.Delete(ctx, &describerDeployment)
if err != nil {
h.logger.Error("failed to delete deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete deployment")
} else {
err = h.kubeClient.Delete(ctx, &describerDeployment)
if err != nil {
h.logger.Error("failed to delete deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete deployment")
}
}

// Manual deployment
Expand All @@ -1229,12 +1241,12 @@ func (h API) DisableIntegrationType(c echo.Context) error {
}, &describerDeploymentManuals)
if err != nil {
h.logger.Error("failed to get manual deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get manual deployment")
}
err = h.kubeClient.Delete(ctx, &describerDeploymentManuals)
if err != nil {
h.logger.Error("failed to delete manual deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete manual deployment")
} else {
err = h.kubeClient.Delete(ctx, &describerDeploymentManuals)
if err != nil {
h.logger.Error("failed to delete manual deployment", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete manual deployment")
}
}

kedaEnabled, ok := os.LookupEnv("KEDA_ENABLED")
Expand All @@ -1250,12 +1262,12 @@ func (h API) DisableIntegrationType(c echo.Context) error {
}, &describerScaledObject)
if err != nil {
h.logger.Error("failed to get scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get scaled object")
}
err = h.kubeClient.Delete(ctx, &describerScaledObject)
if err != nil {
h.logger.Error("failed to delete scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete scaled object")
} else {
err = h.kubeClient.Delete(ctx, &describerScaledObject)
if err != nil {
h.logger.Error("failed to delete scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete scaled object")
}
}

// Manual ScaledObject
Expand All @@ -1266,12 +1278,12 @@ func (h API) DisableIntegrationType(c echo.Context) error {
}, &describerScaledObjectManuals)
if err != nil {
h.logger.Error("failed to get manual scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get manual scaled object")
}
err = h.kubeClient.Delete(ctx, &describerScaledObjectManuals)
if err != nil {
h.logger.Error("failed to delete manual scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete manual scaled object")
} else {
err = h.kubeClient.Delete(ctx, &describerScaledObjectManuals)
if err != nil {
h.logger.Error("failed to delete manual scaled object", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to delete manual scaled object")
}
}
}

Expand Down

0 comments on commit afcf1a4

Please sign in to comment.