Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anil-sarodh committed Jan 10, 2024
1 parent 8b2ca33 commit 9d60fb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
33 changes: 20 additions & 13 deletions capten/agent/internal/capten-store/managed_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,39 @@ import (
)

const (
insertManagedCluster = "INSERT INTO %s.ManagedClusters(id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time) VALUES (?,?,?,?,?,?)"
insertManagedClusterId = "INSERT INTO %s.ManagedClusters(id) VALUES (?)"
updateManagedClusterById = "UPDATE %s.ManagedClusters SET %s WHERE id=?"
deleteManagedClusterById = "DELETE FROM %s.ManagedClusters WHERE id= ?"
selectAllManagedClusters = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters"
selectAllManagedClustersByLabels = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters WHERE %s"
selectGetManagedClusterById = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters WHERE id=%s;"
insertManagedCluster = "INSERT INTO %s.ManagedClusters(id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time) VALUES (?,?,?,?,?,?)"
insertManagedClusterId = "INSERT INTO %s.ManagedClusters(id) VALUES (?)"
updateManagedClusterById = "UPDATE %s.ManagedClusters SET %s WHERE id=?"
deleteManagedClusterById = "DELETE FROM %s.ManagedClusters WHERE id= ?"
selectAllManagedClusters = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters"
selectAllManagedClustersByLabels = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters WHERE %s"
selectGetManagedClusterById = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters WHERE id=%s;"
selectGetManagedClusterByClusterName = "SELECT id, cluster_name, cluster_endpoint, cluster_deploy_status, app_deploy_status, last_update_time FROM %s.ManagedClusters WHERE cluster_name=%s ALLOW FILTERING;"
)

func (a *Store) UpsertManagedCluster(config *captenpluginspb.ManagedCluster) error {
config.LastUpdateTime = time.Now().Format(time.RFC3339)
batch := a.client.Session().NewBatch(gocql.LoggedBatch)
batch.Query(fmt.Sprintf(insertManagedCluster, a.keyspace), config.Id, config.ClusterName, config.ClusterEndpoint, config.ClusterDeployStatus, config.AppDeployStatus, config.LastUpdateTime)
err := a.client.Session().ExecuteBatch(batch)

query := fmt.Sprintf(selectGetManagedClusterByClusterName, a.keyspace, config.ClusterName)
clusters, err := a.executeManagedClustersSelectQuery(query)
if err != nil {
batch.Query(fmt.Sprintf(insertManagedCluster, a.keyspace), config.Id, config.ClusterName, config.ClusterEndpoint, config.ClusterDeployStatus, config.AppDeployStatus, config.LastUpdateTime)
} else if len(clusters) > 0 {
updatePlaceholders, values := formUpdateKvPairsForManagedCluster(config)
if updatePlaceholders == "" {
return err
return fmt.Errorf("empty values found")
}
query := fmt.Sprintf(updateManagedClusterById, a.keyspace, updatePlaceholders)
args := append(values, config.Id)
batch = a.client.Session().NewBatch(gocql.LoggedBatch)
batch.Query(query, args...)
err = a.client.Session().ExecuteBatch(batch)
}
return err

if err := a.client.Session().ExecuteBatch(batch); err != nil {
return err
}

return nil
}

func (a *Store) DeleteManagedClusterById(id string) error {
Expand Down
4 changes: 2 additions & 2 deletions capten/agent/internal/crossplane/cluster_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ func (h *ClusterClaimSyncHandler) triggerClusterDelete(clusterName string, manag
return fmt.Errorf("failed to send event to workflow to configure %s, %v", managedCluster.ClusterEndpoint, err)
}

h.log.Infof("Crossplane project delete %s config workflow %s created", managedCluster.ClusterEndpoint, wkfId)

go h.monitorCrossplaneWorkflow(managedCluster, wkfId)

h.log.Infof("Crossplane project delete %s config workflow %s created", managedCluster.ClusterEndpoint, wkfId)

return nil
}

Expand Down
6 changes: 0 additions & 6 deletions capten/common-pkg/plugins/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ func (g *GitClient) Add(path string) error {
return err
}

s, err := w.Status()
if err != nil {
fmt.Println("Error => " + err.Error())
}
fmt.Printf("Status = \n %+v \n", s)

_, err = w.Add(path)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ func (cp *CrossPlaneApp) configureClusterDelete(ctx context.Context, req *model.
return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to remove cluster folder")
}

err = cp.helper.AddFilesToRepo([]string{"."})
if err != nil {
if err := cp.helper.AddFilesToRepo([]string{"."}); err != nil {
return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to add git repo")
}

Expand Down Expand Up @@ -261,8 +260,6 @@ func removeClusterValues(valuesFileName, clusterName string) error {
}
}

fmt.Printf("newclusters \n %+v \n", newclusters)

clusterConfig.Clusters = &newclusters
jsonBytes, err := json.Marshal(clusterConfig)
if err != nil {
Expand All @@ -274,9 +271,6 @@ func removeClusterValues(valuesFileName, clusterName string) error {
return err
}

fmt.Println("final file")
fmt.Printf("%s \n", string(yamlBytes))

err = os.WriteFile(valuesFileName, yamlBytes, os.ModeAppend)
return err
}
Expand Down

0 comments on commit 9d60fb2

Please sign in to comment.