Skip to content

Commit

Permalink
cluster claim update workflow in config-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
indresh-28 authored and vramk23 committed Nov 25, 2023
1 parent e789abc commit de4c84f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
40 changes: 40 additions & 0 deletions capten/config-worker/internal/crossplane/argocd_app_values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package crossplane

type Source struct {
RepoURL string `json:"repoURL,omitempty"`
TargetRevision string `json:"targetRevision,omitempty"`
}

type Dest struct {
Server string `json:"server,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

type GlobalValues struct {
ClusterConfigPath string `json:"clusterConfigPath,omitempty"`
}

type DefaultApps struct {
Name string `json:"name,omitempty"`
ValuesPath string `json:"valuesPath,omitempty"`
RepoURL string `json:"repoURL,omitempty"`
Namespace string `json:"namespace,omitempty"`
Chart string `json:"chart,omitempty"`
TargetRevision string `json:"targetRevision,omitempty"`
}

type Cluster struct {
Name string `json:"name,omitempty"`
Server string `json:"server,omitempty"`
DefApps []DefaultApps `json:"defaultApps,omitempty"`
}

type ArgoCDAppValue struct {
Project string `json:"project,omitempty"`
Global GlobalValues `json:"global,omitempty"`
Src Source `json:"source,omitempty"`
Destination Dest `json:"destination,omitempty"`
SyncPolicy interface{} `json:"syncPolicy,omitempty"`
Compositions interface{} `json:"compositions,omitempty"`
Clusters *[]Cluster `json:"clusters,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getAppNameNamespace(ctx context.Context, fileName string) (string, string,

func (cp *CrossPlaneApp) configureClusterUpdate(ctx context.Context, req *model.CrossplaneClusterUpdate) (status string, err error) {
logger.Infof("configuring the cluster endpoint for %s", req.RepoURL)
endpoint, err := cp.helper.CreateCluster(ctx, req.Name, req.ManagedK8SId)
endpoint, err := cp.helper.CreateCluster(ctx, req.ManagedK8SId, req.Name)
if err != nil {
return string(agentmodel.WorkFlowStatusFailed), errors.WithMessage(err, "failed to CreateCluster in argocd app")
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func updateClusterEndpointDetials(filename, clusterName, clusterEndpoint, defaul
return err
}

var argoCDAppValue model.ArgoCDAppValue
var argoCDAppValue ArgoCDAppValue

err = json.Unmarshal(jsonData, &argoCDAppValue)
if err != nil {
Expand All @@ -125,7 +125,7 @@ func updateClusterEndpointDetials(filename, clusterName, clusterEndpoint, defaul

for index := range defaultApps {
localObj := &defaultApps[index]
strings.ReplaceAll(localObj.AppConfigPath, clusterNameSub, clusterName)
strings.ReplaceAll(localObj.ValuesPath, clusterNameSub, clusterName)
}

logger.Infof("udpated the req endpoint details to %s for name %s ", clusterEndpoint, clusterName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ func readCrossPlanePluginConfig(pluginFile string) (*crossplanePluginConfig, err
return &pluginData, nil
}

func readClusterDefaultApps(clusterDefaultApp string) ([]model.DefaultApps, error) {
func readClusterDefaultApps(clusterDefaultApp string) ([]DefaultApps, error) {
data, err := os.ReadFile(filepath.Clean(clusterDefaultApp))
if err != nil {
return nil, fmt.Errorf("failed to read clusterDefaultApp File: %s, err: %w", clusterDefaultApp, err)
}

var defaultApps []model.DefaultApps
var defaultApps []DefaultApps
err = json.Unmarshal(data, &defaultApps)
if err != nil {
return nil, fmt.Errorf("%w", err)
Expand Down
34 changes: 0 additions & 34 deletions capten/model/config_workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,3 @@ type CrossplaneClusterUpdate struct {
ManagedK8SId string `json:"managedK8SId,omitempty"`
RepoURL string `json:"repoURL,omitempty"`
}

type Source struct {
RepoURL string `json:"repoURL,omitempty"`
TargetRevision string `json:"targetRevision,omitempty"`
}

type Dest struct {
Server string `json:"server,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

type DefaultApps struct {
Name string `json:"name,omitempty"`
AppConfigPath string `json:"appConfigPath,omitempty"`
RepoURL string `json:"repoURL,omitempty"`
Namespace string `json:"namespace,omitempty"`
Chart string `json:"chart,omitempty"`
TargetRevision string `json:"targetRevision,omitempty"`
}
type Cluster struct {
Name string `json:"name,omitempty"`
ConfigPath string `json:"configPath,omitempty"`
Server string `json:"server,omitempty"`
DefApps []DefaultApps `json:"defaultApps,omitempty"`
}

type ArgoCDAppValue struct {
Project string `json:"project,omitempty"`
Src Source `json:"source,omitempty"`
Destination Dest `json:"destination,omitempty"`
SyncPolicy interface{} `json:"syncPolicy,omitempty"`
Compositions interface{} `json:"compositions,omitempty"`
Clusters *[]Cluster `json:"clusters,omitempty"`
}

0 comments on commit de4c84f

Please sign in to comment.