Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anil-sarodh committed Nov 20, 2023
1 parent fd14fc0 commit 6bd9da1
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 2 deletions.
8 changes: 6 additions & 2 deletions capten/agent/internal/api/plugin_crossplane_provider_apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ func (a *Agent) UpdateCrossplanProvider(ctx context.Context, request *captenplug
Status: captenpluginspb.StatusCode_INTERNAL_ERROR,
StatusMessage: "failed to get crossplane provider for " + request.Id,
}, nil
}
if project == nil {
} else if project == nil {
return &captenpluginspb.UpdateCrossplanProviderResponse{
Status: captenpluginspb.StatusCode_NOT_FOUND,
StatusMessage: "Crossplane provider is not available for" + request.Id,
}, nil
} else if project.CloudType != request.CloudType {
return &captenpluginspb.UpdateCrossplanProviderResponse{
Status: captenpluginspb.StatusCode_INVALID_ARGUMENT,
StatusMessage: "Crossplane provider cloud type change is not supported for" + request.Id,
}, nil
}

provider := model.CrossplaneProvider{
Expand Down
95 changes: 95 additions & 0 deletions capten/common-pkg/plugins/argocd/clusters.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,97 @@
package argocd

import (
"context"

"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/util/io"
)

func (a *ArgoCDClient) CreateCluster(ctx context.Context, clusterReq *Cluster) (*v1alpha1.Cluster, error) {
conn, appClient, err := a.client.NewClusterClient()
if err != nil {
return nil, err
}
defer io.Close(conn)

resp, err := appClient.Create(ctx, &cluster.ClusterCreateRequest{
Cluster: &v1alpha1.Cluster{
Server: clusterReq.Server,
Name: clusterReq.Name,
Config: v1alpha1.ClusterConfig{
Username: clusterReq.Config.Username,
Password: clusterReq.Config.Password,
TLSClientConfig: v1alpha1.TLSClientConfig{
Insecure: clusterReq.Config.Insecure,
ServerName: clusterReq.Config.ServerName,
CertData: clusterReq.Config.CertData,
KeyData: clusterReq.Config.KeyData,
CAData: clusterReq.Config.CAData,
},
},
ConnectionState: v1alpha1.ConnectionState{
Status: clusterReq.ConnectionState.Status,
Message: clusterReq.ConnectionState.Message,
},
Namespaces: clusterReq.Namespaces,
},
})
if err != nil {
return nil, err
}
return resp, nil
}

func (a *ArgoCDClient) DeleteCluster(ctx context.Context, clusterURL string) (*cluster.ClusterResponse, error) {
conn, appClient, err := a.client.NewClusterClient()
if err != nil {
return nil, err
}
defer io.Close(conn)

resp, err := appClient.Delete(ctx, &cluster.ClusterQuery{
Id: &cluster.ClusterID{
Value: clusterURL,
},
})
if err != nil {
return nil, err
}

return resp, nil
}

func (a *ArgoCDClient) GetCluster(ctx context.Context, clusterURL string) (*v1alpha1.Cluster, error) {
conn, appClient, err := a.client.NewClusterClient()
if err != nil {
return nil, err
}
defer io.Close(conn)

repository, err := appClient.Get(ctx, &cluster.ClusterQuery{
Id: &cluster.ClusterID{
Value: clusterURL,
},
})
if err != nil {
return nil, err
}

return repository, nil
}

func (a *ArgoCDClient) ListClusters(ctx context.Context) (*v1alpha1.ClusterList, error) {
conn, appClient, err := a.client.NewClusterClient()
if err != nil {
return nil, err
}
defer io.Close(conn)

list, err := appClient.List(ctx, &cluster.ClusterQuery{})
if err != nil {
return nil, err
}

return list, nil
}
35 changes: 35 additions & 0 deletions capten/common-pkg/plugins/argocd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,38 @@ type Repository struct {
InsecureIgnoreHostKey bool `json:"InsecureIgnoreHostKey"`
ConnectionState ConnectionState `json:"ConnectionState"`
}

type TLSClientConfig struct {
// Insecure specifies that the server should be accessed without verifying the TLS certificate. For testing only.
Insecure bool `json:"insecure" `
// ServerName is passed to the server for SNI and is used in the client to check server
// certificates against. If ServerName is empty, the hostname used to contact the
// server is used.
ServerName string `json:"serverName,omitempty" `
// CertData holds PEM-encoded bytes (typically read from a client certificate file).
// CertData takes precedence over CertFile
CertData []byte `json:"certData,omitempty" `
// KeyData holds PEM-encoded bytes (typically read from a client certificate key file).
// KeyData takes precedence over KeyFile
KeyData []byte `json:"keyData,omitempty" `
// CAData holds PEM-encoded bytes (typically read from a root certificates bundle).
// CAData takes precedence over CAFile
CAData []byte `json:"caData,omitempty" `
}

type ClusterConfig struct {
// Server requires Basic authentication
Username string `json:"username,omitempty" `
Password string `json:"password,omitempty"`

// TLSClientConfig contains settings to enable transport layer security
TLSClientConfig `json:"tlsClientConfig"`
}

type Cluster struct {
Server string `json:"server"`
Name string `json:"name"`
Config ClusterConfig `json:"config"`
ConnectionState ConnectionState `json:"ConnectionState"`
Namespaces []string `json:"namespaces,omitempty"`
}

0 comments on commit 6bd9da1

Please sign in to comment.