|
@@ -36,61 +36,45 @@ func NewCreateResourceHandler(
|
|
|
decoderValidator: shared.NewDefaultRequestDecoderValidator(config.Logger, config.Alerter),
|
|
decoderValidator: shared.NewDefaultRequestDecoderValidator(config.Logger, config.Alerter),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func (c *CreateResourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
func (c *CreateResourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
// read the infra from the attached scope
|
|
// read the infra from the attached scope
|
|
|
infra, _ := r.Context().Value(types.InfraScope).(*models.Infra)
|
|
infra, _ := r.Context().Value(types.InfraScope).(*models.Infra)
|
|
|
operation, _ := r.Context().Value(types.OperationScope).(*models.Operation)
|
|
operation, _ := r.Context().Value(types.OperationScope).(*models.Operation)
|
|
|
-
|
|
|
|
|
req := &ptypes.CreateResourceRequest{}
|
|
req := &ptypes.CreateResourceRequest{}
|
|
|
-
|
|
|
|
|
if ok := c.decoderValidator.DecodeAndValidate(w, r, req); !ok {
|
|
if ok := c.decoderValidator.DecodeAndValidate(w, r, req); !ok {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// update the operation to indicate completion
|
|
// update the operation to indicate completion
|
|
|
operation.Status = "completed"
|
|
operation.Status = "completed"
|
|
|
-
|
|
|
|
|
operation, err := c.Config.Repo.Infra().UpdateOperation(operation)
|
|
operation, err := c.Config.Repo.Infra().UpdateOperation(operation)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// push to the operation stream
|
|
// push to the operation stream
|
|
|
err = redis_stream.SendOperationCompleted(c.Config.RedisClient, infra, operation)
|
|
err = redis_stream.SendOperationCompleted(c.Config.RedisClient, infra, operation)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// push to the global stream
|
|
// push to the global stream
|
|
|
err = redis_stream.PushToGlobalStream(c.Config.RedisClient, infra, operation, "created")
|
|
err = redis_stream.PushToGlobalStream(c.Config.RedisClient, infra, operation, "created")
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// update the infra to indicate completion
|
|
// update the infra to indicate completion
|
|
|
infra.Status = "created"
|
|
infra.Status = "created"
|
|
|
-
|
|
|
|
|
infra, err = c.Config.Repo.Infra().UpdateInfra(infra)
|
|
infra, err = c.Config.Repo.Infra().UpdateInfra(infra)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// switch on the kind of resource and write the corresponding objects to the database
|
|
// switch on the kind of resource and write the corresponding objects to the database
|
|
|
switch req.Kind {
|
|
switch req.Kind {
|
|
|
case string(types.InfraEKS), string(types.InfraDOKS), string(types.InfraGKE), string(types.InfraAKS):
|
|
case string(types.InfraEKS), string(types.InfraDOKS), string(types.InfraGKE), string(types.InfraAKS):
|
|
|
var cluster *models.Cluster
|
|
var cluster *models.Cluster
|
|
|
-
|
|
|
|
|
cluster, err = createCluster(c.Config, infra, operation, req.Output)
|
|
cluster, err = createCluster(c.Config, infra, operation, req.Output)
|
|
|
-
|
|
|
|
|
if cluster != nil {
|
|
if cluster != nil {
|
|
|
c.Config.AnalyticsClient.Track(analytics.ClusterProvisioningSuccessTrack(
|
|
c.Config.AnalyticsClient.Track(analytics.ClusterProvisioningSuccessTrack(
|
|
|
&analytics.ClusterProvisioningSuccessTrackOpts{
|
|
&analytics.ClusterProvisioningSuccessTrackOpts{
|
|
@@ -115,7 +99,6 @@ func (c *CreateResourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
|
|
|
case string(types.InfraACR):
|
|
case string(types.InfraACR):
|
|
|
_, err = createACRRegistry(c.Config, infra, operation, req.Output)
|
|
_, err = createACRRegistry(c.Config, infra, operation, req.Output)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
apierrors.HandleAPIError(c.Config.Logger, c.Config.Alerter, w, r, apierrors.NewErrInternal(err), true)
|
|
|
return
|
|
return
|
|
@@ -129,10 +112,8 @@ func createECRRegistry(config *config.Config, infra *models.Infra, operation *mo
|
|
|
InfraID: infra.ID,
|
|
InfraID: infra.ID,
|
|
|
Name: output["name"].(string),
|
|
Name: output["name"].(string),
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// parse raw data into ECR type
|
|
// parse raw data into ECR type
|
|
|
awsInt, err := config.Repo.AWSIntegration().ReadAWSIntegration(reg.ProjectID, reg.AWSIntegrationID)
|
|
awsInt, err := config.Repo.AWSIntegration().ReadAWSIntegration(reg.ProjectID, reg.AWSIntegrationID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
@@ -150,33 +131,24 @@ func createECRRegistry(config *config.Config, infra *models.Infra, operation *mo
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
reg.URL = *authOutput.AuthorizationData[0].ProxyEndpoint
|
|
reg.URL = *authOutput.AuthorizationData[0].ProxyEndpoint
|
|
|
-
|
|
|
|
|
reg, err = config.Repo.Registry().CreateRegistry(reg)
|
|
reg, err = config.Repo.Registry().CreateRegistry(reg)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return reg, nil
|
|
return reg, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createRDSDatabase(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Database, error) {
|
|
func createRDSDatabase(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Database, error) {
|
|
|
// check for infra id being 0 as a safeguard so that all non-provisioned
|
|
// check for infra id being 0 as a safeguard so that all non-provisioned
|
|
|
// clusters are not matched by read
|
|
// clusters are not matched by read
|
|
|
if infra.ID == 0 {
|
|
if infra.ID == 0 {
|
|
|
return nil, fmt.Errorf("infra id cannot be 0")
|
|
return nil, fmt.Errorf("infra id cannot be 0")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
var database *models.Database
|
|
var database *models.Database
|
|
|
var err error
|
|
var err error
|
|
|
var isNotFound bool
|
|
var isNotFound bool
|
|
|
-
|
|
|
|
|
database, err = config.Repo.Database().ReadDatabaseByInfraID(infra.ProjectID, infra.ID)
|
|
database, err = config.Repo.Database().ReadDatabaseByInfraID(infra.ProjectID, infra.ID)
|
|
|
-
|
|
|
|
|
isNotFound = err != nil && errors.Is(err, gorm.ErrRecordNotFound)
|
|
isNotFound = err != nil && errors.Is(err, gorm.ErrRecordNotFound)
|
|
|
-
|
|
|
|
|
if isNotFound {
|
|
if isNotFound {
|
|
|
database = &models.Database{
|
|
database = &models.Database{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
@@ -187,127 +159,95 @@ func createRDSDatabase(config *config.Config, infra *models.Infra, operation *mo
|
|
|
} else if err != nil {
|
|
} else if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
database.InstanceID = output["rds_instance_id"].(string)
|
|
database.InstanceID = output["rds_instance_id"].(string)
|
|
|
database.InstanceEndpoint = output["rds_connection_endpoint"].(string)
|
|
database.InstanceEndpoint = output["rds_connection_endpoint"].(string)
|
|
|
database.InstanceName = output["rds_instance_name"].(string)
|
|
database.InstanceName = output["rds_instance_name"].(string)
|
|
|
-
|
|
|
|
|
if isNotFound {
|
|
if isNotFound {
|
|
|
database, err = config.Repo.Database().CreateDatabase(database)
|
|
database, err = config.Repo.Database().CreateDatabase(database)
|
|
|
} else {
|
|
} else {
|
|
|
database, err = config.Repo.Database().UpdateDatabase(database)
|
|
database, err = config.Repo.Database().UpdateDatabase(database)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
infra.DatabaseID = database.ID
|
|
infra.DatabaseID = database.ID
|
|
|
infra, err = config.Repo.Infra().UpdateInfra(infra)
|
|
infra, err = config.Repo.Infra().UpdateInfra(infra)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
lastApplied := make(map[string]interface{})
|
|
lastApplied := make(map[string]interface{})
|
|
|
-
|
|
|
|
|
err = json.Unmarshal(operation.LastApplied, &lastApplied)
|
|
err = json.Unmarshal(operation.LastApplied, &lastApplied)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
err = createRDSEnvGroup(config, infra, database, lastApplied)
|
|
err = createRDSEnvGroup(config, infra, database, lastApplied)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return database, nil
|
|
return database, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createS3Bucket(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) error {
|
|
func createS3Bucket(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) error {
|
|
|
lastApplied := make(map[string]interface{})
|
|
lastApplied := make(map[string]interface{})
|
|
|
-
|
|
|
|
|
err := json.Unmarshal(operation.LastApplied, &lastApplied)
|
|
err := json.Unmarshal(operation.LastApplied, &lastApplied)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return createS3EnvGroup(config, infra, lastApplied, output)
|
|
return createS3EnvGroup(config, infra, lastApplied, output)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createCluster(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Cluster, error) {
|
|
func createCluster(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Cluster, error) {
|
|
|
// check for infra id being 0 as a safeguard so that all non-provisioned
|
|
// check for infra id being 0 as a safeguard so that all non-provisioned
|
|
|
// clusters are not matched by read
|
|
// clusters are not matched by read
|
|
|
if infra.ID == 0 {
|
|
if infra.ID == 0 {
|
|
|
return nil, fmt.Errorf("infra id cannot be 0")
|
|
return nil, fmt.Errorf("infra id cannot be 0")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
var cluster *models.Cluster
|
|
var cluster *models.Cluster
|
|
|
var err error
|
|
var err error
|
|
|
var isNotFound bool
|
|
var isNotFound bool
|
|
|
-
|
|
|
|
|
// look for cluster matching infra in database; if the cluster already exists, update the cluster but
|
|
// look for cluster matching infra in database; if the cluster already exists, update the cluster but
|
|
|
// don't add it again
|
|
// don't add it again
|
|
|
cluster, err = config.Repo.Cluster().ReadClusterByInfraID(infra.ProjectID, infra.ID)
|
|
cluster, err = config.Repo.Cluster().ReadClusterByInfraID(infra.ProjectID, infra.ID)
|
|
|
-
|
|
|
|
|
isNotFound = err != nil && errors.Is(err, gorm.ErrRecordNotFound)
|
|
isNotFound = err != nil && errors.Is(err, gorm.ErrRecordNotFound)
|
|
|
-
|
|
|
|
|
if isNotFound {
|
|
if isNotFound {
|
|
|
cluster = getNewCluster(infra)
|
|
cluster = getNewCluster(infra)
|
|
|
} else if err != nil {
|
|
} else if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
caData, err := transformClusterCAData([]byte(output["cluster_ca_data"].(string)))
|
|
caData, err := transformClusterCAData([]byte(output["cluster_ca_data"].(string)))
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// if cluster_token is output and infra is azure, update the azure integration
|
|
// if cluster_token is output and infra is azure, update the azure integration
|
|
|
if _, exists := output["cluster_token"]; exists && infra.AzureIntegrationID != 0 {
|
|
if _, exists := output["cluster_token"]; exists && infra.AzureIntegrationID != 0 {
|
|
|
azInt, err := config.Repo.AzureIntegration().ReadAzureIntegration(infra.ProjectID, infra.AzureIntegrationID)
|
|
azInt, err := config.Repo.AzureIntegration().ReadAzureIntegration(infra.ProjectID, infra.AzureIntegrationID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
azInt.AKSPassword = []byte(output["cluster_token"].(string))
|
|
azInt.AKSPassword = []byte(output["cluster_token"].(string))
|
|
|
-
|
|
|
|
|
azInt, err = config.Repo.AzureIntegration().OverwriteAzureIntegration(azInt)
|
|
azInt, err = config.Repo.AzureIntegration().OverwriteAzureIntegration(azInt)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// only update the cluster name if this is during creation - we don't want to overwrite the cluster name
|
|
// only update the cluster name if this is during creation - we don't want to overwrite the cluster name
|
|
|
// which may have been manually set
|
|
// which may have been manually set
|
|
|
if isNotFound {
|
|
if isNotFound {
|
|
|
cluster.Name = output["cluster_name"].(string)
|
|
cluster.Name = output["cluster_name"].(string)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
cluster.Server = output["cluster_endpoint"].(string)
|
|
cluster.Server = output["cluster_endpoint"].(string)
|
|
|
cluster.CertificateAuthorityData = caData
|
|
cluster.CertificateAuthorityData = caData
|
|
|
-
|
|
|
|
|
if isNotFound {
|
|
if isNotFound {
|
|
|
cluster, err = config.Repo.Cluster().CreateCluster(cluster)
|
|
cluster, err = config.Repo.Cluster().CreateCluster(cluster)
|
|
|
} else {
|
|
} else {
|
|
|
cluster, err = config.Repo.Cluster().UpdateCluster(cluster)
|
|
cluster, err = config.Repo.Cluster().UpdateCluster(cluster)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return cluster, nil
|
|
return cluster, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func getNewCluster(infra *models.Infra) *models.Cluster {
|
|
func getNewCluster(infra *models.Infra) *models.Cluster {
|
|
|
res := &models.Cluster{
|
|
res := &models.Cluster{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
|
InfraID: infra.ID,
|
|
InfraID: infra.ID,
|
|
|
MonitorHelmReleases: true,
|
|
MonitorHelmReleases: true,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
switch infra.Kind {
|
|
switch infra.Kind {
|
|
|
case types.InfraEKS:
|
|
case types.InfraEKS:
|
|
|
res.AuthMechanism = models.AWS
|
|
res.AuthMechanism = models.AWS
|
|
@@ -322,30 +262,22 @@ func getNewCluster(infra *models.Infra) *models.Cluster {
|
|
|
res.AuthMechanism = models.Azure
|
|
res.AuthMechanism = models.Azure
|
|
|
res.AzureIntegrationID = infra.AzureIntegrationID
|
|
res.AzureIntegrationID = infra.AzureIntegrationID
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func transformClusterCAData(ca []byte) ([]byte, error) {
|
|
func transformClusterCAData(ca []byte) ([]byte, error) {
|
|
|
re := regexp.MustCompile(`^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$`)
|
|
re := regexp.MustCompile(`^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$`)
|
|
|
-
|
|
|
|
|
// if it matches the base64 regex, decode it
|
|
// if it matches the base64 regex, decode it
|
|
|
caData := string(ca)
|
|
caData := string(ca)
|
|
|
-
|
|
|
|
|
if re.MatchString(caData) {
|
|
if re.MatchString(caData) {
|
|
|
decoded, err := base64.StdEncoding.DecodeString(caData)
|
|
decoded, err := base64.StdEncoding.DecodeString(caData)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return []byte(decoded), nil
|
|
return []byte(decoded), nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// otherwise just return the CA
|
|
// otherwise just return the CA
|
|
|
return ca, nil
|
|
return ca, nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createDOCRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
func createDOCRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
|
reg := &models.Registry{
|
|
reg := &models.Registry{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
@@ -354,10 +286,8 @@ func createDOCRRegistry(config *config.Config, infra *models.Infra, operation *m
|
|
|
URL: output["url"].(string),
|
|
URL: output["url"].(string),
|
|
|
Name: output["name"].(string),
|
|
Name: output["name"].(string),
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createGCRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
func createGCRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
|
reg := &models.Registry{
|
|
reg := &models.Registry{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
@@ -366,10 +296,8 @@ func createGCRRegistry(config *config.Config, infra *models.Infra, operation *mo
|
|
|
URL: output["url"].(string),
|
|
URL: output["url"].(string),
|
|
|
Name: "gcr-registry",
|
|
Name: "gcr-registry",
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createGARRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
func createGARRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
|
reg := &models.Registry{
|
|
reg := &models.Registry{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
@@ -378,10 +306,8 @@ func createGARRegistry(config *config.Config, infra *models.Infra, operation *mo
|
|
|
URL: output["url"].(string),
|
|
URL: output["url"].(string),
|
|
|
Name: "gar-registry",
|
|
Name: "gar-registry",
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createACRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
func createACRRegistry(config *config.Config, infra *models.Infra, operation *models.Operation, output map[string]interface{}) (*models.Registry, error) {
|
|
|
reg := &models.Registry{
|
|
reg := &models.Registry{
|
|
|
ProjectID: infra.ProjectID,
|
|
ProjectID: infra.ProjectID,
|
|
@@ -390,38 +316,29 @@ func createACRRegistry(config *config.Config, infra *models.Infra, operation *mo
|
|
|
URL: output["url"].(string),
|
|
URL: output["url"].(string),
|
|
|
Name: output["name"].(string),
|
|
Name: output["name"].(string),
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
return config.Repo.Registry().CreateRegistry(reg)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createRDSEnvGroup(config *config.Config, infra *models.Infra, database *models.Database, lastApplied map[string]interface{}) error {
|
|
func createRDSEnvGroup(config *config.Config, infra *models.Infra, database *models.Database, lastApplied map[string]interface{}) error {
|
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
|
Repo: config.Repo,
|
|
Repo: config.Repo,
|
|
|
DigitalOceanOAuth: config.DOConf,
|
|
DigitalOceanOAuth: config.DOConf,
|
|
|
Cluster: cluster,
|
|
Cluster: cluster,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// split the instance endpoint on the port
|
|
// split the instance endpoint on the port
|
|
|
port := "5432"
|
|
port := "5432"
|
|
|
host := database.InstanceEndpoint
|
|
host := database.InstanceEndpoint
|
|
|
-
|
|
|
|
|
if strArr := strings.Split(database.InstanceEndpoint, ":"); len(strArr) == 2 {
|
|
if strArr := strings.Split(database.InstanceEndpoint, ":"); len(strArr) == 2 {
|
|
|
host = strArr[0]
|
|
host = strArr[0]
|
|
|
port = strArr[1]
|
|
port = strArr[1]
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
_, err = envgroup.CreateEnvGroup(agent, types.ConfigMapInput{
|
|
_, err = envgroup.CreateEnvGroup(agent, types.ConfigMapInput{
|
|
|
Name: fmt.Sprintf("rds-credentials-%s", lastApplied["db_name"].(string)),
|
|
Name: fmt.Sprintf("rds-credentials-%s", lastApplied["db_name"].(string)),
|
|
|
Namespace: "default",
|
|
Namespace: "default",
|
|
@@ -433,61 +350,45 @@ func createRDSEnvGroup(config *config.Config, infra *models.Infra, database *mod
|
|
|
"PGUSER": lastApplied["db_user"].(string),
|
|
"PGUSER": lastApplied["db_user"].(string),
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func deleteRDSEnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}) error {
|
|
func deleteRDSEnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}) error {
|
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
|
Repo: config.Repo,
|
|
Repo: config.Repo,
|
|
|
DigitalOceanOAuth: config.DOConf,
|
|
DigitalOceanOAuth: config.DOConf,
|
|
|
Cluster: cluster,
|
|
Cluster: cluster,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
err = envgroup.DeleteEnvGroup(agent, fmt.Sprintf("rds-credentials-%s", lastApplied["db_name"].(string)), "default")
|
|
err = envgroup.DeleteEnvGroup(agent, fmt.Sprintf("rds-credentials-%s", lastApplied["db_name"].(string)), "default")
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func createS3EnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}, output map[string]interface{}) error {
|
|
func createS3EnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}, output map[string]interface{}) error {
|
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
|
Repo: config.Repo,
|
|
Repo: config.Repo,
|
|
|
DigitalOceanOAuth: config.DOConf,
|
|
DigitalOceanOAuth: config.DOConf,
|
|
|
Cluster: cluster,
|
|
Cluster: cluster,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// split the instance endpoint on the port
|
|
// split the instance endpoint on the port
|
|
|
_, err = envgroup.CreateEnvGroup(agent, types.ConfigMapInput{
|
|
_, err = envgroup.CreateEnvGroup(agent, types.ConfigMapInput{
|
|
|
Name: fmt.Sprintf("s3-credentials-%s", lastApplied["bucket_name"].(string)),
|
|
Name: fmt.Sprintf("s3-credentials-%s", lastApplied["bucket_name"].(string)),
|
|
@@ -499,38 +400,28 @@ func createS3EnvGroup(config *config.Config, infra *models.Infra, lastApplied ma
|
|
|
"S3_BUCKET_NAME": output["s3_bucket_name"].(string),
|
|
"S3_BUCKET_NAME": output["s3_bucket_name"].(string),
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to create S3 env group: %s", err.Error())
|
|
return fmt.Errorf("failed to create S3 env group: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
func deleteS3EnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}) error {
|
|
func deleteS3EnvGroup(config *config.Config, infra *models.Infra, lastApplied map[string]interface{}) error {
|
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
cluster, err := config.Repo.Cluster().ReadCluster(infra.ProjectID, infra.ParentClusterID)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
ooc := &kubernetes.OutOfClusterConfig{
|
|
|
Repo: config.Repo,
|
|
Repo: config.Repo,
|
|
|
DigitalOceanOAuth: config.DOConf,
|
|
DigitalOceanOAuth: config.DOConf,
|
|
|
Cluster: cluster,
|
|
Cluster: cluster,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
agent, err := kubernetes.GetAgentOutOfClusterConfig(ooc)
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
return fmt.Errorf("failed to get agent: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
err = envgroup.DeleteEnvGroup(agent, fmt.Sprintf("s3-credentials-%s", lastApplied["bucket_name"].(string)), "default")
|
|
err = envgroup.DeleteEnvGroup(agent, fmt.Sprintf("s3-credentials-%s", lastApplied["bucket_name"].(string)), "default")
|
|
|
-
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
return fmt.Errorf("failed to create RDS env group: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|