Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into marcin/prod-2389-cli-…
Browse files Browse the repository at this point in the history
…command-to-set-pipeline-context
  • Loading branch information
maciaszczykm committed Aug 28, 2024
2 parents cb15a1b + 617bfd8 commit 82fd08a
Show file tree
Hide file tree
Showing 35 changed files with 575 additions and 390 deletions.
140 changes: 4 additions & 136 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: us-east-2
# role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
# role-session-name: PluralCLI
# - name: setup kubectl
# uses: azure/setup-kubectl@v3
# - name: Get EKS credentials
# run: aws eks update-kubeconfig --name pluraldev
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -41,34 +31,6 @@ jobs:
type=sha
type=ref,event=pr
type=ref,event=branch
# - name: Set up Docker Buildx
# id: builder
# uses: docker/setup-buildx-action@v3
# with:
# # cleanup: true
# # driver: kubernetes
# platforms: linux/amd64
# driver-opts: |
# namespace=buildx
# requests.cpu=1.5
# requests.memory=3.5Gi
# "nodeselector=plural.sh/scalingGroup=buildx-spot-x86"
# "tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"
# - name: Append ARM buildx builder from AWS
# run: |
# docker buildx create \
# --append \
# --bootstrap \
# --name ${{ steps.builder.outputs.name }} \
# --driver=kubernetes \
# --platform linux/arm64 \
# --node=${{ steps.builder.outputs.name }}-arm64 \
# --buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" \
# --driver-opt namespace=buildx \
# --driver-opt requests.cpu=1.5 \
# --driver-opt requests.memory=3.5Gi \
# '--driver-opt="nodeselector=plural.sh/scalingGroup=buildx-spot-arm64"' \
# '--driver-opt="tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand Down Expand Up @@ -136,16 +98,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
role-session-name: PluralCLI
- name: setup kubectl
uses: azure/setup-kubectl@v3
- name: Get EKS credentials
run: aws eks update-kubeconfig --name pluraldev
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -158,34 +110,10 @@ jobs:
type=sha
type=ref,event=pr
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: builder
uses: docker/setup-buildx-action@v3
with:
cleanup: true
driver: kubernetes
platforms: linux/amd64
driver-opts: |
namespace=buildx
requests.cpu=1.5
requests.memory=3.5Gi
"nodeselector=plural.sh/scalingGroup=buildx-spot-x86"
"tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"
- name: Append ARM buildx builder from AWS
run: |
docker buildx create \
--append \
--bootstrap \
--name ${{ steps.builder.outputs.name }} \
--driver=kubernetes \
--platform linux/arm64 \
--node=${{ steps.builder.outputs.name }}-arm64 \
--buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" \
--driver-opt namespace=buildx \
--driver-opt requests.cpu=1.5 \
--driver-opt requests.memory=3.5Gi \
'--driver-opt="nodeselector=plural.sh/scalingGroup=buildx-spot-arm64"' \
'--driver-opt="tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"'
- name: Login to GHCR
uses: docker/login-action@v2
with:
Expand Down Expand Up @@ -225,19 +153,6 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
if: always()
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
role-session-name: PluralCLI
- name: Manually cleanup buildx
if: always()
run: |
docker buildx stop ${{ steps.builder.outputs.name }}
sleep 10
docker buildx rm ${{ steps.builder.outputs.name }}
dind:
name: Build dind image
runs-on: ubuntu-latest
Expand All @@ -250,16 +165,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
role-session-name: PluralCLI
- name: setup kubectl
uses: azure/setup-kubectl@v3
- name: Get EKS credentials
run: aws eks update-kubeconfig --name pluraldev
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -272,34 +177,10 @@ jobs:
type=sha
type=ref,event=pr
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: builder
uses: docker/setup-buildx-action@v3
with:
cleanup: true
driver: kubernetes
platforms: linux/amd64
driver-opts: |
namespace=buildx
requests.cpu=1.5
requests.memory=3.5Gi
"nodeselector=plural.sh/scalingGroup=buildx-spot-x86"
"tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"
- name: Append ARM buildx builder from AWS
run: |
docker buildx create \
--append \
--bootstrap \
--name ${{ steps.builder.outputs.name }} \
--driver=kubernetes \
--platform linux/arm64 \
--node=${{ steps.builder.outputs.name }}-arm64 \
--buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" \
--driver-opt namespace=buildx \
--driver-opt requests.cpu=1.5 \
--driver-opt requests.memory=3.5Gi \
'--driver-opt="nodeselector=plural.sh/scalingGroup=buildx-spot-arm64"' \
'--driver-opt="tolerations=key=plural.sh/capacityType,value=SPOT,effect=NoSchedule;key=plural.sh/reserved,value=BUILDX,effect=NoSchedule"'
- name: Login to GHCR
uses: docker/login-action@v2
with:
Expand Down Expand Up @@ -339,19 +220,6 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
if: always()
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::312272277431:role/github-actions/buildx-deployments
role-session-name: PluralCLI
- name: Manually cleanup buildx
if: always()
run: |
docker buildx stop ${{ steps.builder.outputs.name }}
sleep 10
docker buildx rm ${{ steps.builder.outputs.name }}
trivy-scan:
name: Trivy fs scan
runs-on: ubuntu-latest
Expand Down
14 changes: 12 additions & 2 deletions cmd/command/cd/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Commands(clients client.Plural, helmConfiguration *action.Configuration) []
},
{
Name: "login",
Action: p.handleCdLogin,
Action: p.HandleCdLogin,
Usage: "logs into your plural console",
Flags: []cli.Flag{
cli.StringFlag{Name: "url", Usage: "console url"},
Expand Down Expand Up @@ -224,7 +224,17 @@ func confirmCluster(url, token string) (bool, error) {
return common.Confirm(fmt.Sprintf("Are you sure you want to install deploy operator for the cluster:\nName: %s\nHandle: %s\nProvider: %s\n", myCluster.MyCluster.Name, handle, provider), "PLURAL_INSTALL_AGENT_CONFIRM"), nil
}

func (p *Plural) handleCdLogin(c *cli.Context) (err error) {
func (p *Plural) HandleCdLogin(c *cli.Context) (err error) {
prior := console.ReadConfig()
if prior.Url != "" {
if common.Affirm(
fmt.Sprintf("You've already configured your console at %s, continue using those credentials?", prior.Url),
"PLURAL_CD_USE_EXISTING_CREDENTIALS",
) {
return
}
}

url := c.String("url")
if url == "" {
url, err = utils.ReadLine("Enter the url of your console: ")
Expand Down
39 changes: 21 additions & 18 deletions cmd/command/cd/cd_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,24 @@ func (p *Plural) handleListClusters(_ *cli.Context) error {
})
}

func (p *Plural) GetClusterId(handle string) (string, string, error) {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return "", "", err
}

existing, err := p.ConsoleClient.GetCluster(nil, lo.ToPtr(handle))
if err != nil {
return "", "", err
}

return existing.ID, existing.Name, nil
}

func (p *Plural) handleDescribeCluster(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}
existing, err := p.ConsoleClient.GetCluster(getIdAndName(c.Args().Get(0)))
existing, err := p.ConsoleClient.GetCluster(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand All @@ -177,7 +190,7 @@ func (p *Plural) handleUpdateCluster(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}
existing, err := p.ConsoleClient.GetCluster(getIdAndName(c.Args().Get(0)))
existing, err := p.ConsoleClient.GetCluster(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand Down Expand Up @@ -227,7 +240,7 @@ func (p *Plural) handleDeleteCluster(c *cli.Context) error {
return err
}

existing, err := p.ConsoleClient.GetCluster(getIdAndName(c.Args().Get(0)))
existing, err := p.ConsoleClient.GetCluster(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand All @@ -248,7 +261,7 @@ func (p *Plural) handleGetClusterCredentials(c *cli.Context) error {
return err
}

cluster, err := p.ConsoleClient.GetCluster(getIdAndName(c.Args().Get(0)))
cluster, err := p.ConsoleClient.GetCluster(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand Down Expand Up @@ -339,16 +352,6 @@ func (p *Plural) handleCreateCluster(c *cli.Context) error {
return nil
}

func getIdAndName(input string) (id, name *string) {
if strings.HasPrefix(input, "@") {
h := strings.Trim(input, "@")
name = &h
} else {
id = &input
}
return
}

func (p *Plural) handleCreateProvider(existingProviders []string) (*gqlclient.CreateClusterProvider, error) {
provider := ""
var resp struct {
Expand Down Expand Up @@ -393,11 +396,11 @@ func (p *Plural) handleClusterReinstall(c *cli.Context) error {
return err
}

id, name := getIdAndName(c.Args().Get(0))
return p.reinstallOperator(c, id, name)
id, name := common.GetIdAndName(c.Args().Get(0))
return p.ReinstallOperator(c, id, name)
}

func (p *Plural) reinstallOperator(c *cli.Context, id, handle *string) error {
func (p *Plural) ReinstallOperator(c *cli.Context, id, handle *string) error {
deployToken, err := p.ConsoleClient.GetDeployToken(id, handle)
if err != nil {
return err
Expand Down Expand Up @@ -456,7 +459,7 @@ func (p *Plural) handleClusterBootstrap(c *cli.Context) error {
if attrs.Handle != nil {
handle = attrs.Handle
}
return p.reinstallOperator(c, nil, handle)
return p.ReinstallOperator(c, nil, handle)
}

return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/command/cd/cd_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (p *Plural) handleListClusterServices(c *cli.Context) error {
if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}
sd, err := p.ConsoleClient.ListClusterServices(getIdAndName(c.Args().Get(0)))
sd, err := p.ConsoleClient.ListClusterServices(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
}
}

clusterId, clusterName := getIdAndName(c.Args().Get(0))
clusterId, clusterName := common.GetIdAndName(c.Args().Get(0))
sd, err := p.ConsoleClient.CreateClusterService(clusterId, clusterName, attributes)
if err != nil {
return err
Expand Down Expand Up @@ -283,7 +283,7 @@ func (p *Plural) handleCloneClusterService(c *cli.Context) error {
return err
}

cluster, err := p.ConsoleClient.GetCluster(getIdAndName(c.Args().Get(0)))
cluster, err := p.ConsoleClient.GetCluster(common.GetIdAndName(c.Args().Get(0)))
if err != nil {
return err
}
Expand Down
15 changes: 13 additions & 2 deletions cmd/command/pr/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ func (p *Plural) handleCreatePrAutomation(c *cli.Context) error {
return err
}
var branch, context *string
var prID string
id, name := common.GetIdAndName(c.Args().Get(0))
if id != nil {
prID = *id
}
if name != nil {
pr, err := p.ConsoleClient.GetPrAutomationByName(*name)
if err != nil {
return err
}
prID = pr.ID
}

id := c.Args().Get(0)
if c := c.String("context"); c != "" {
if c == "-" {
bytes, err := io.ReadAll(os.Stdin)
Expand All @@ -117,7 +128,7 @@ func (p *Plural) handleCreatePrAutomation(c *cli.Context) error {
branch = &b
}

pr, err := p.ConsoleClient.CreatePullRequest(id, branch, context)
pr, err := p.ConsoleClient.CreatePullRequest(prID, branch, context)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 82fd08a

Please sign in to comment.