Skip to content

Commit

Permalink
Merge pull request #28 from equinor/185798-update-go-modules
Browse files Browse the repository at this point in the history
update go modules
  • Loading branch information
nilsgstrabo authored Feb 23, 2022
2 parents 2a1382a + f713f03 commit 8bf9b32
Show file tree
Hide file tree
Showing 25 changed files with 664 additions and 1,048 deletions.
2 changes: 1 addition & 1 deletion cmd/buildDeployApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var buildDeployApplicationCmd = &cobra.Command{
follow, _ := cmd.Flags().GetBool("follow")

if appName == nil || *appName == "" || branch == "" {
return errors.New("Application name and branch are required")
return errors.New("application name and branch are required")
}

apiClient, err := client.GetForCommand(cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var createCmd = &cobra.Command{
Short: "Create Radix resources",
Long: `A longer description .`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to create")
return errors.New("please specify the resource you want to create")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/createApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var createApplicationCmd = &cobra.Command{
wbs, _ := cmd.Flags().GetString("wbs")

if appName == nil || *appName == "" || repository == "" || owner == "" || configBranch == "" || wbs == "" {
return errors.New("Application name, repository, owner, WBS and config branch are required fields")
return errors.New("application name, repository, owner, WBS and config branch are required fields")
}

adGroups, _ := cmd.Flags().GetStringSlice("ad-groups")
Expand Down
2 changes: 1 addition & 1 deletion cmd/createEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var createEnvironmentCmd = &cobra.Command{
envName, err := cmd.Flags().GetString("environment")

if err != nil || appName == nil || *appName == "" {
return errors.New("Environment name and application name are required fields")
return errors.New("environment name and application name are required fields")
}

parameters := environment.NewCreateEnvironmentParams().
Expand Down
2 changes: 1 addition & 1 deletion cmd/createJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var createJobCmd = &cobra.Command{
Short: "Create job command",
Long: `Will be the main command for triggering pipelines.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the pipeline you want to create")
return errors.New("please specify the pipeline you want to create")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var deleteCmd = &cobra.Command{
Short: "Delete Radix resources",
Long: `Will delete a Radix resource.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to delete")
return errors.New("please specify the resource you want to delete")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/deleteApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var deleteApplicationCmd = &cobra.Command{
}

if appName == nil || *appName == "" {
return errors.New("Application name is a required field")
return errors.New("application name is a required field")
}

deleteApplicationParams := application.NewDeleteApplicationParams()
Expand Down
2 changes: 1 addition & 1 deletion cmd/deleteEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var deleteEnvironmentCmd = &cobra.Command{
envName, err := cmd.Flags().GetString("environment")

if err != nil || appName == nil || *appName == "" {
return errors.New("Environment name and application name are required fields")
return errors.New("environment name and application name are required fields")
}

parameters := environment.NewDeleteEnvironmentParams().
Expand Down
2 changes: 1 addition & 1 deletion cmd/deployApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var deployApplicationCmd = &cobra.Command{
follow, _ := cmd.Flags().GetBool("follow")

if appName == nil || *appName == "" || targetEnvironment == "" {
return errors.New("Application name and target environment are required")
return errors.New("application name and target environment are required")
}

apiClient, err := client.GetForCommand(cmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var getCmd = &cobra.Command{
Short: "Get Radix resource",
Long: `Will be used to get any Radix resource.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to get")
return errors.New("please specify the resource you want to get")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/getBranchEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var getBranchEnvironmentCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
fromConfig, _ := cmd.Flags().GetBool(settings.FromConfigOption)
if !fromConfig {
return errors.New("Config can only come from radixconfig file in current folder")
return errors.New("config can only come from radixconfig file in current folder")
}

_, err := getRadixApplicationFromFile()
Expand Down
2 changes: 1 addition & 1 deletion cmd/getConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var getConfigCmd = &cobra.Command{
Short: "Get setting from Radix config",
Long: `Helper functionality to get data from radixconfig.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the setting you want to get")
return errors.New("please specify the setting you want to get")
},
}

Expand Down
5 changes: 1 addition & 4 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ package cmd

import (
"errors"
"time"

"github.com/spf13/cobra"
)

const logsEnabled = true

const deltaRefreshOutput = 50 * time.Millisecond

// logsCmd represents the list command
var logsCmd = &cobra.Command{
Use: "logs",
Short: "Follow Radix logs for Radix resource",
Long: `Feeds resource output to the console while it runs.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to get logs for")
return errors.New("please specify the resource you want to get logs for")
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/logsEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ var logsEnvironmentCmd = &cobra.Command{
}

if appName == nil || *appName == "" {
return errors.New("Application name is required")
return errors.New("application name is required")
}

environmentName, _ := cmd.Flags().GetString("environment")

if environmentName == "" {
return errors.New("Both `environment` and `component` are required")
return errors.New("both `environment` and `component` are required")
}

apiClient, err := client.GetForCommand(cmd)
Expand Down Expand Up @@ -74,7 +74,7 @@ func getComponentReplicasForEnvironment(apiClient *apiclient.Radixapi, appName,
}

if environmentDetails == nil || environmentDetails.Payload.ActiveDeployment == nil {
return nil, errors.New("Active deployment was not found in environment")
return nil, errors.New("active deployment was not found in environment")
}

componentReplicas := make(map[string][]string)
Expand Down
80 changes: 37 additions & 43 deletions cmd/logsEnvironmentComponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"github.com/spf13/cobra"
)

const logsEnvironmentComponentEnabled = false

// logsEnvironmentComponentCmd represents the logsEnvironmentComponentCmd command
var logsEnvironmentComponentCmd = &cobra.Command{
Use: "component",
Expand All @@ -43,14 +41,14 @@ var logsEnvironmentComponentCmd = &cobra.Command{
}

if appName == nil || *appName == "" {
return errors.New("Application name is required")
return errors.New("application name is required")
}

environmentName, _ := cmd.Flags().GetString("environment")
componentName, _ := cmd.Flags().GetString("component")

if environmentName == "" || componentName == "" {
return errors.New("Both `environment` and `component` are required")
return errors.New("both `environment` and `component` are required")
}

apiClient, err := client.GetForCommand(cmd)
Expand Down Expand Up @@ -78,52 +76,48 @@ func logForComponentReplicas(cmd *cobra.Command, apiClient *apiclient.Radixapi,
// Somtimes, even though we get delta, the log is the same as previous
previousLogForReplica := make(map[string]string)

for {
select {
case <-refreshLog:

i := 0
for componentName, replicas := range componentReplicas {
for _, replica := range replicas {
now := time.Now()
sinceTime := now.Add(-settings.DeltaRefreshApplication)
since := strfmt.DateTime(sinceTime)

logParameters := component.NewLogParams()
logParameters.WithAppName(appName)
logParameters.WithDeploymentName("irrelevant")
logParameters.WithComponentName(componentName)
logParameters.WithPodName(replica)
logParameters.SetSinceTime(&since)

logData, err := apiClient.Component.Log(logParameters, nil)
for range refreshLog {
i := 0
for componentName, replicas := range componentReplicas {
for _, replica := range replicas {
now := time.Now()
sinceTime := now.Add(-settings.DeltaRefreshApplication)
since := strfmt.DateTime(sinceTime)

logParameters := component.NewLogParams()
logParameters.WithAppName(appName)
logParameters.WithDeploymentName("irrelevant")
logParameters.WithComponentName(componentName)
logParameters.WithPodName(replica)
logParameters.SetSinceTime(&since)

logData, err := apiClient.Component.Log(logParameters, nil)
if err != nil {
// Replicas may have died
_, newReplicas, err := getReplicasForComponent(apiClient, appName, environmentName, componentName)
if err != nil {
// Replicas may have died
_, newReplicas, err := getReplicasForComponent(apiClient, appName, environmentName, componentName)
if err != nil {
return err
}
return err
}

componentReplicas[componentName] = newReplicas
break

componentReplicas[componentName] = newReplicas
break

} else {
// Somtimes, even though we get delta, the log is the same as previous
if !strings.EqualFold(logData.Payload, previousLogForReplica[replica]) {
logLines := strings.Split(strings.Replace(strings.TrimRight(logData.Payload, "\r\n"), "\r\n", "\n", -1), "\n")
if len(logLines) > 0 {
log.PrintLines(cmd, replica, []string{}, logLines, log.GetColor(i))
previousLogForReplica[replica] = logData.Payload
}
} else {
// Somtimes, even though we get delta, the log is the same as previous
if len(logData.Payload) > 0 && !strings.EqualFold(logData.Payload, previousLogForReplica[replica]) {
logLines := strings.Split(strings.Replace(strings.TrimRight(logData.Payload, "\r\n"), "\r\n", "\n", -1), "\n")
if len(logLines) > 0 {
log.PrintLines(cmd, replica, []string{}, logLines, log.GetColor(i))
previousLogForReplica[replica] = logData.Payload
}
}

i++
}

i++
}
}

}
return nil
}

func getReplicasForComponent(apiClient *apiclient.Radixapi, appName, environmentName, componentName string) (*string, []string, error) {
Expand All @@ -139,7 +133,7 @@ func getReplicasForComponent(apiClient *apiclient.Radixapi, appName, environment

var deploymentName string
if environmentDetails == nil || environmentDetails.Payload.ActiveDeployment == nil {
return nil, nil, errors.New("Active deployment was not found in environment")
return nil, nil, errors.New("active deployment was not found in environment")
}

var replicas []string
Expand Down
2 changes: 1 addition & 1 deletion cmd/logsJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var logsJobCmd = &cobra.Command{
}

if appName == nil || *appName == "" {
return errors.New("Application name is required")
return errors.New("application name is required")
}

jobName, _ := cmd.Flags().GetString("job")
Expand Down
2 changes: 1 addition & 1 deletion cmd/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var restartCmd = &cobra.Command{
Short: "Restart Radix resources",
Long: `Restart Radix resources.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to restart")
return errors.New("please specify the resource you want to restart")
},
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/restartComponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"errors"
"fmt"

"github.com/equinor/radix-cli/generated-client/client/component"
"github.com/equinor/radix-cli/pkg/client"
"github.com/spf13/cobra"
Expand All @@ -41,12 +42,12 @@ var restartComponentCmd = &cobra.Command{
envName, err := cmd.Flags().GetString("environment")

if err != nil || appName == nil || *appName == "" {
return errors.New("Environment name and application name are required fields")
return errors.New("environment name and application name are required fields")
}

cmpName, err := cmd.Flags().GetString("component")
if err != nil {
return errors.New("Component name is a required field")
return errors.New("component name is a required field")
}

parameters := component.NewRestartComponentParams().
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func getEnvironmentFromConfig(cmd *cobra.Command, branchName string) (*string, e
}
}

return nil, fmt.Errorf("No environment found which maps to branch name `%s`", branchName)
return nil, fmt.Errorf("no environment found which maps to branch name `%s`", branchName)
}

func getRadixApplicationFromFile() (*v1.RadixApplication, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var setCmd = &cobra.Command{
Short: "Sets values in Radix",
Long: `Used for updating resources in Radix.`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("Please specify the resource you want to set")
return errors.New("please specify the resource you want to set")
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/setContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var setContextCmd = &cobra.Command{
name, _ := cmd.Flags().GetString(settings.ContextOption)

if !radixconfig.IsValidContext(name) {
return fmt.Errorf("Context '%s' is not a valid context", name)
return fmt.Errorf("context '%s' is not a valid context", name)
}

radixConfig := radixconfig.RadixConfigAccess{}
Expand Down
12 changes: 6 additions & 6 deletions cmd/setEnvironmentSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ var setEnvironmentSecretCmd = &cobra.Command{
}

if appName == nil || *appName == "" {
return errors.New("Application name is required")
return errors.New("application name is required")
}

secretName, _ := cmd.Flags().GetString(secretOption)
secretValue, _ := cmd.Flags().GetString(valueOption)

if secretName == "" {
return errors.New("Secret is required")
return errors.New("secret is required")
}

if secretValue == "" {
return errors.New("Value is required")
return errors.New("value is required")
}

environmentName, _ := cmd.Flags().GetString(environmentOption)
Expand All @@ -80,21 +80,21 @@ var setEnvironmentSecretCmd = &cobra.Command{
})

if !reconciledOk {
return errors.New("Component was not reconciled within time")
return errors.New("component was not reconciled within time")
}
}

componentSecret := models.SecretParameters{}
componentSecret.SecretValue = &secretValue

changeComponentSecretParameters := environment.NewChangeEnvironmentComponentSecretParams()
changeComponentSecretParameters := environment.NewChangeComponentSecretParams()
changeComponentSecretParameters.SetAppName(*appName)
changeComponentSecretParameters.SetEnvName(environmentName)
changeComponentSecretParameters.SetComponentName(component)
changeComponentSecretParameters.SetSecretName(secretName)
changeComponentSecretParameters.SetComponentSecret(&componentSecret)

_, err = apiClient.Environment.ChangeEnvironmentComponentSecret(changeComponentSecretParameters, nil)
_, err = apiClient.Environment.ChangeComponentSecret(changeComponentSecretParameters, nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8bf9b32

Please sign in to comment.