Skip to content

Commit 2a448d4

Browse files
authored
Update Upgrade Command (#144)
* Update Upgrade Command Signed-off-by: nagesh bansal <[email protected]> * Rename ops/ and types/agent_types.go Signed-off-by: nagesh bansal <[email protected]> * Add Usage_0.23.0.md link in Readme Signed-off-by: nagesh bansal <[email protected]> --------- Signed-off-by: nagesh bansal <[email protected]>
1 parent 30cb3ca commit 2a448d4

File tree

9 files changed

+57
-51
lines changed

9 files changed

+57
-51
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For more information including a complete list of litmusctl operations, see the
1111
* For v0.12.0 or latest:
1212
* Non-Interactive mode: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage.md">Click here</a>
1313
* Interactive mode: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_interactive.md">Click here</a>
14+
* For 0.23.0: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_0.23.0.md">Click here</a>
1415
* For v0.2.0 or earlier && compatible with Litmus-2.0.0-Beta8 or earlier: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_v0.2.0.md">Click here</a>
1516

1617
## Requirements

pkg/apis/upgrade.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ type manifestData struct {
2626
}
2727

2828
type data struct {
29-
GetManifest string `json:"getManifest"`
29+
GetManifest string `json:"getInfraManifest"`
3030
}
3131

32-
type InfrasData struct {
33-
Data GetInfraDetails `json:"data"`
32+
type GetInfraResponse struct {
33+
Data GetInfraData `json:"data"`
3434
Errors []struct {
3535
Message string `json:"message"`
3636
Path []string `json:"path"`
3737
} `json:"errors"`
3838
}
3939

40-
type GetInfraDetails struct {
41-
GetInfraDetails InfrasDetails `json:"getAgentDetails"`
40+
type GetInfraData struct {
41+
GetInfraDetails InfraDetails `json:"getInfraDetails"`
4242
}
4343

44-
type InfrasDetails struct {
44+
type InfraDetails struct {
4545
InfraID string `json:"infraID"`
4646
InfraNamespace *string `json:"infraNamespace"`
4747
}
4848

4949
func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, infraID string, kubeconfig string) (string, error) {
5050

51-
// Query to fetch agent details from server
51+
// Query to fetch Infra details from server
5252
query := `{"query":"query {\n getInfraDetails(infraID : \"` + infraID + `\", \n projectID : \"` + projectID + `\"){\n infraNamespace infraID \n}}"}`
5353
resp, err := SendRequest(SendRequestParams{Endpoint: cred.Endpoint + utils.GQLAPIPath, Token: cred.Token}, []byte(query), string(types.Post))
5454
if err != nil {
@@ -61,7 +61,7 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i
6161
}
6262

6363
defer resp.Body.Close()
64-
var infra InfrasData
64+
var infra GetInfraResponse
6565

6666
if resp.StatusCode == http.StatusOK {
6767
err = json.Unmarshal(bodyBytes, &infra)
@@ -102,27 +102,27 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i
102102
}
103103

104104
// To write the manifest data into a temporary file
105-
err = ioutil.WriteFile("chaos-delegate-manifest.yaml", []byte(manifest.Data.GetManifest), 0644)
105+
err = ioutil.WriteFile("chaos-infra-manifest.yaml", []byte(manifest.Data.GetManifest), 0644)
106106
if err != nil {
107107
return "", err
108108
}
109109

110-
// Fetching agent-config from the subscriber
111-
configData, err := k8s.GetConfigMap(c, "agent-config", *infra.Data.GetInfraDetails.InfraNamespace)
110+
// Fetching subscriber-config from the subscriber
111+
configData, err := k8s.GetConfigMap(c, "subscriber-config", *infra.Data.GetInfraDetails.InfraNamespace)
112112
if err != nil {
113113
return "", err
114114
}
115115
var configMapString string
116116

117117
metadata := new(bytes.Buffer)
118118
fmt.Fprintf(metadata, "\n%s: %s\n%s: %s\n%s: \n %s: %s\n %s: %s\n%s:\n", "apiVersion", "v1",
119-
"kind", "ConfigMap", "metadata", "name", "agent-config", "namespace", *infra.Data.GetInfraDetails.InfraNamespace, "data")
119+
"kind", "ConfigMap", "metadata", "name", "subscriber-config", "namespace", *infra.Data.GetInfraDetails.InfraNamespace, "data")
120120

121121
for k, v := range configData {
122122
b := new(bytes.Buffer)
123123
if k == "COMPONENTS" {
124124
fmt.Fprintf(b, " %s: |\n %s", k, v)
125-
} else if k == "START_TIME" || k == "IS_CLUSTER_CONFIRMED" {
125+
} else if k == "START_TIME" || k == "IS_INFRA_CONFIRMED" {
126126
fmt.Fprintf(b, " %s: \"%s\"\n", k, v)
127127
} else {
128128
fmt.Fprintf(b, " %s: %s\n", k, v)
@@ -134,30 +134,30 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i
134134
yamlOutput, err := k8s.ApplyYaml(k8s.ApplyYamlPrams{
135135
Token: cred.Token,
136136
Endpoint: cred.Endpoint,
137-
YamlPath: "chaos-delegate-manifest.yaml",
137+
YamlPath: "chaos-infra-manifest.yaml",
138138
}, kubeconfig, true)
139139

140140
if err != nil {
141141
return "", err
142142
}
143143
utils.White.Print("\n", yamlOutput)
144144

145-
err = os.Remove("chaos-delegate-manifest.yaml")
145+
err = os.Remove("chaos-infra-manifest.yaml")
146146
if err != nil {
147-
return "Error removing Chaos Delegate manifest: ", err
147+
return "Error removing Chaos Infrastructure manifest: ", err
148148
}
149149

150-
// Creating a backup for current agent-config in the SUBSCRIBER
150+
// Creating a backup for current subscriber-config in the SUBSCRIBER
151151
home, err := homedir.Dir()
152152
cobra.CheckErr(err)
153153

154154
configMapString = metadata.String() + configMapString
155-
err = ioutil.WriteFile(home+"/backupAgentConfig.yaml", []byte(configMapString), 0644)
155+
err = ioutil.WriteFile(home+"/backupSubscriberConfig.yaml", []byte(configMapString), 0644)
156156
if err != nil {
157-
return "Error creating backup for agent config: ", err
157+
return "Error creating backup for subscriber config: ", err
158158
}
159159

160-
utils.White_B.Print("\n ** A backup of agent-config configmap has been saved in your system's home directory as backupAgentConfig.yaml **\n")
160+
utils.White_B.Print("\n ** A backup of subscriber-config configmap has been saved in your system's home directory as backupSubscriberConfig.yaml **\n")
161161

162162
return "Manifest applied successfully", nil
163163
} else {

pkg/cmd/connect/infra.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"os"
2323

2424
"github.com/litmuschaos/litmusctl/pkg/apis"
25+
"github.com/litmuschaos/litmusctl/pkg/infra_ops"
2526
"github.com/litmuschaos/litmusctl/pkg/k8s"
26-
"github.com/litmuschaos/litmusctl/pkg/ops"
2727
"github.com/litmuschaos/litmusctl/pkg/types"
2828
"github.com/litmuschaos/litmusctl/pkg/utils"
2929

@@ -79,7 +79,7 @@ var infraCmd = &cobra.Command{
7979

8080
if !projectExists {
8181
utils.White_B.Print("Creating a random project...")
82-
newInfra.ProjectId = ops.CreateRandomProject(credentials)
82+
newInfra.ProjectId = infra_ops.CreateRandomProject(credentials)
8383
}
8484
}
8585

@@ -166,14 +166,14 @@ var infraCmd = &cobra.Command{
166166

167167
// Check if user has sufficient permissions based on mode
168168
utils.White_B.Print("\n🏃 Running prerequisites check....")
169-
ops.ValidateSAPermissions(newInfra.Namespace, newInfra.Mode, &kubeconfig)
169+
infra_ops.ValidateSAPermissions(newInfra.Namespace, newInfra.Mode, &kubeconfig)
170170

171171
// Check if infra already exists
172-
isInfraExist, err, infraList := ops.ValidateInfraNameExists(newInfra.InfraName, newInfra.ProjectId, credentials)
172+
isInfraExist, err, infraList := infra_ops.ValidateInfraNameExists(newInfra.InfraName, newInfra.ProjectId, credentials)
173173
utils.PrintError(err)
174174

175175
if isInfraExist {
176-
ops.PrintExistingInfra(infraList)
176+
infra_ops.PrintExistingInfra(infraList)
177177
os.Exit(1)
178178
}
179179
envIDs, err := environment.GetEnvironmentList(newInfra.ProjectId, credentials)
@@ -190,7 +190,7 @@ var infraCmd = &cobra.Command{
190190
}
191191
if !isEnvExist {
192192
utils.Red.Println("\nChaos Environment with the given ID doesn't exists.")
193-
ops.PrintExistingEnvironments(envIDs)
193+
infra_ops.PrintExistingEnvironments(envIDs)
194194
utils.White_B.Println("\n❗ Please enter a name from the List or Create a new environment using `litmusctl create chaos-environment`")
195195
os.Exit(1)
196196
}
@@ -201,25 +201,25 @@ var infraCmd = &cobra.Command{
201201

202202
if newInfra.ProjectId == "" {
203203
// Fetch project id
204-
newInfra.ProjectId = ops.GetProjectID(userDetails)
204+
newInfra.ProjectId = infra_ops.GetProjectID(userDetails)
205205
}
206206

207-
modeType := ops.GetModeType()
207+
modeType := infra_ops.GetModeType()
208208

209209
// Check if user has sufficient permissions based on mode
210210
utils.White_B.Print("\n🏃 Running prerequisites check....")
211-
ops.ValidateSAPermissions(newInfra.Namespace, modeType, &kubeconfig)
212-
newInfra, err = ops.GetInfraDetails(modeType, newInfra.ProjectId, credentials, &kubeconfig)
211+
infra_ops.ValidateSAPermissions(newInfra.Namespace, modeType, &kubeconfig)
212+
newInfra, err = infra_ops.GetInfraDetails(modeType, newInfra.ProjectId, credentials, &kubeconfig)
213213
utils.PrintError(err)
214214

215215
newInfra.ServiceAccount, newInfra.SAExists = k8s.ValidSA(newInfra.Namespace, &kubeconfig)
216216
newInfra.Mode = modeType
217217
}
218218

219-
ops.Summary(newInfra, &kubeconfig)
219+
infra_ops.Summary(newInfra, &kubeconfig)
220220

221221
if !nonInteractive {
222-
ops.ConfirmInstallation()
222+
infra_ops.ConfirmInstallation()
223223
}
224224

225225
infra, err := infrastructure.ConnectInfra(newInfra, credentials)

pkg/cmd/create/environment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
2121
"github.com/litmuschaos/litmusctl/pkg/apis"
2222
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
23-
"github.com/litmuschaos/litmusctl/pkg/ops"
23+
"github.com/litmuschaos/litmusctl/pkg/infra_ops"
2424
"github.com/litmuschaos/litmusctl/pkg/utils"
2525
"github.com/spf13/cobra"
2626
"os"
@@ -109,7 +109,7 @@ var environmentCmd = &cobra.Command{
109109
}
110110
if isEnvExist {
111111
utils.Red.Println("\nChaos Environment with the given ID already exists, try with a different name")
112-
ops.PrintExistingEnvironments(envs)
112+
infra_ops.PrintExistingEnvironments(envs)
113113
os.Exit(1)
114114
}
115115

pkg/cmd/upgrade/agent.go renamed to pkg/cmd/upgrade/infra.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ import (
1919
"context"
2020
"fmt"
2121
"os"
22+
"strings"
2223

2324
"github.com/litmuschaos/litmusctl/pkg/apis"
2425
"github.com/litmuschaos/litmusctl/pkg/utils"
2526
"github.com/spf13/cobra"
2627
)
2728

2829
// createCmd represents the create command
29-
var agentCmd = &cobra.Command{
30-
Use: "chaos-delegate",
31-
Short: `Upgrades the LitmusChaos agent plane.`,
30+
var infraCmd = &cobra.Command{
31+
Use: "chaos-infra",
32+
Short: `Upgrades the LitmusChaos Execution plane.`,
3233
Run: func(cmd *cobra.Command, args []string) {
3334
credentials, err := utils.GetCredentials(cmd)
3435
utils.PrintError(err)
@@ -41,29 +42,33 @@ var agentCmd = &cobra.Command{
4142
fmt.Scanln(&projectID)
4243
}
4344

44-
cluster_id, err := cmd.Flags().GetString("chaos-delegate-id")
45+
infraID, err := cmd.Flags().GetString("chaos-infra-id")
4546
utils.PrintError(err)
4647

47-
if cluster_id == "" {
48-
utils.White_B.Print("\nEnter the Chaos Delegate ID: ")
49-
fmt.Scanln(&cluster_id)
48+
if infraID == "" {
49+
utils.White_B.Print("\nEnter the Chaos Infra ID: ")
50+
fmt.Scanln(&infraID)
5051
}
5152

5253
kubeconfig, err := cmd.Flags().GetString("kubeconfig")
5354
utils.PrintError(err)
5455

55-
output, err := apis.UpgradeInfra(context.Background(), credentials, projectID, cluster_id, kubeconfig)
56+
output, err := apis.UpgradeInfra(context.Background(), credentials, projectID, infraID, kubeconfig)
5657
if err != nil {
57-
utils.Red.Print("\n❌ Failed upgrading Chaos Delegate: \n" + err.Error() + "\n")
58+
if strings.Contains(err.Error(), "no documents in result") {
59+
utils.Red.Println("❌ The specified Project ID or Chaos Infrastructure ID doesn't exist.")
60+
os.Exit(1)
61+
}
62+
utils.Red.Print("\n❌ Failed upgrading Chaos Infrastructure: \n" + err.Error() + "\n")
5863
os.Exit(1)
5964
}
6065
utils.White_B.Print("\n", output)
6166
},
6267
}
6368

6469
func init() {
65-
UpgradeCmd.AddCommand(agentCmd)
66-
agentCmd.Flags().String("project-id", "", "Enter the project ID")
67-
agentCmd.Flags().String("kubeconfig", "", "Enter the kubeconfig path(default: $HOME/.kube/config))")
68-
agentCmd.Flags().String("chaos-delegate-id", "", "Enter the Chaos Delegate ID")
70+
UpgradeCmd.AddCommand(infraCmd)
71+
infraCmd.Flags().String("project-id", "", "Enter the project ID")
72+
infraCmd.Flags().String("kubeconfig", "", "Enter the kubeconfig path(default: $HOME/.kube/config))")
73+
infraCmd.Flags().String("chaos-infra-id", "", "Enter the Chaos Infrastructure ID")
6974
}

pkg/cmd/upgrade/upgrade.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
var UpgradeCmd = &cobra.Command{
2424
Use: "upgrade",
2525
Short: `Examples:
26-
#upgrade version of your Chaos Delegate
27-
litmusctl upgrade chaos-delegate --chaos-delegate-id="4cc25543-36c8-4373-897b-2e5dbbe87bcf" --project-id="d861b650-1549-4574-b2ba-ab754058dd04" --non-interactive
26+
#upgrade version of your Chaos Infrastructure
27+
litmusctl upgrade chaos-infra --chaos-infra-id="4cc25543-36c8-4373-897b-2e5dbbe87bcf" --project-id="d861b650-1549-4574-b2ba-ab754058dd04" --non-interactive
2828
2929
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
3030
`,

pkg/ops/ops.go renamed to pkg/infra_ops/ops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package ops
16+
package infra_ops
1717

1818
import (
1919
"fmt"

pkg/ops/platform.go renamed to pkg/infra_ops/platform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
package ops
16+
package infra_ops
1717

1818
import (
1919
"context"
File renamed without changes.

0 commit comments

Comments
 (0)