Skip to content

Commit

Permalink
fix: tweaks (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Sep 27, 2023
1 parent 94272c3 commit 19a91db
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/controller/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (clctrl *ClusterController) DetokenizeKMSKeyID() error {
}

if err := pkg.ReplaceFileContent(
fmt.Sprintf("%s/%s/%s/components/vault/application.yaml", clctrl.ProviderConfig.GitopsDir, registryPath, clctrl.ClusterName),
fmt.Sprintf("%s/%s/components/vault/application.yaml", clctrl.ProviderConfig.GitopsDir, registryPath),
"<AWS_KMS_KEY_ID>",
awsKmsKeyId,
); err != nil {
Expand Down
11 changes: 8 additions & 3 deletions internal/controller/kubefirst.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (clctrl *ClusterController) ExportClusterRecord() error {
cluster, err := clctrl.MdbCl.GetCluster(clctrl.ClusterName)
if err != nil {
log.Errorf("Error exporting cluster record: %s", err)
clctrl.HandleError(err.Error())
return err
}

Expand All @@ -40,6 +41,9 @@ func (clctrl *ClusterController) ExportClusterRecord() error {
err = runtime.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", consoleCloudUrl), "kubefirst api")
if err != nil {
log.Error("unable to start kubefirst api")

clctrl.HandleError(err.Error())
return err
}

requestObject := pkgtypes.ProxyImportRequest{
Expand All @@ -52,12 +56,14 @@ func (clctrl *ClusterController) ExportClusterRecord() error {

payload, err := json.Marshal(requestObject)
if err != nil {
clctrl.HandleError(err.Error())
return err
}

req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/proxy", consoleCloudUrl), bytes.NewReader(payload))
if err != nil {
log.Errorf("error %s", err)
clctrl.HandleError(err.Error())
return err
}
req.Header.Add("Content-Type", "application/json")
Expand All @@ -71,15 +77,14 @@ func (clctrl *ClusterController) ExportClusterRecord() error {

if res.StatusCode != http.StatusOK {
log.Errorf("unable to import cluster %s", res.Status)
clctrl.HandleError(err.Error())
return errors.New(fmt.Sprintf("unable to import cluster %s", res.Status))
}

body, err := io.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
if err != nil {
return err
}

log.Infof("Import: %s", string(body))

return nil
}
4 changes: 4 additions & 0 deletions internal/controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
stateStoreData = pkgtypes.StateStoreCredentials{
AccessKeyID: clctrl.AWSAuth.AccessKeyID,
SecretAccessKey: clctrl.AWSAuth.SecretAccessKey,
SessionToken: clctrl.AWSAuth.SessionToken,
Name: clctrl.KubefirstStateStoreBucketName,
}

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "state_store_details", pkgtypes.StateStoreDetails{
AWSStateStoreBucket: strings.ReplaceAll(*kubefirstStateStoreBucket.Location, "/", ""),
AWSArtifactsBucket: strings.ReplaceAll(*kubefirstArtifactsBucket.Location, "/", ""),
Hostname: "s3.amazonaws.com",
Name: clctrl.KubefirstStateStoreBucketName,
})
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions providers/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func CreateCivoCluster(definition *pkgtypes.ClusterDefinition) error {
err = ctrl.ExportClusterRecord()
if err != nil {
log.Errorf("Error exporting cluster record: %s", err)
ctrl.HandleError(err.Error())
return err
} else {
err = ctrl.MdbCl.UpdateCluster(ctrl.ClusterName, "status", constants.ClusterStatusProvisioned)
Expand Down

0 comments on commit 19a91db

Please sign in to comment.