forked from openshift/rosa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Juan Hernandez <jhernand@redhat.com>
- Loading branch information
Showing
15 changed files
with
709 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
/moactl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Changes | ||
|
||
This document describes the relevant changes between releases of the `moactl` | ||
command line tool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# Copyright (c) 2020 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Ensure go modules are enabled: | ||
export GO111MODULE=on | ||
export GOPROXY=https://proxy.golang.org | ||
|
||
# Disable CGO so that we always generate static binaries: | ||
export CGO_ENABLED=0 | ||
|
||
.PHONY: moactl | ||
moactl: | ||
go build . | ||
|
||
.PHONY: test | ||
test: | ||
ginkgo -r cmd pkg | ||
|
||
.PHONY: fmt | ||
fmt: | ||
gofmt -s -l -w cmd pkg | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint run | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf \ | ||
moactl \ | ||
*-darwin-amd64 \ | ||
*-linux-amd64 \ | ||
*-windows-amd64 \ | ||
*.sha256 \ | ||
$(NULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= MOA Command Line Tool | ||
|
||
This project contains the `moactl` command line tool that simplifies the use of | ||
the _MOA_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright (c) 2020 Red Hat, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cluster | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"gitlab.cee.redhat.com/service/moactl/cmd/cluster/create" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "cluster COMMAND", | ||
Short: "Perform cluster operations", | ||
Long: "Perform cluster operations.", | ||
} | ||
|
||
func init() { | ||
Cmd.AddCommand(create.Cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
Copyright (c) 2020 Red Hat, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package create | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/openshift-online/ocm-sdk-go" | ||
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
"github.com/spf13/cobra" | ||
|
||
"gitlab.cee.redhat.com/service/moactl/pkg/debug" | ||
rprtr "gitlab.cee.redhat.com/service/moactl/pkg/reporter" | ||
) | ||
|
||
var args struct { | ||
region string | ||
} | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "create [FLAGS] NAME", | ||
Short: "Create cluster", | ||
Long: "Create cluster.", | ||
Run: run, | ||
} | ||
|
||
func init() { | ||
fs := Cmd.Flags() | ||
fs.StringVar( | ||
&args.region, | ||
"region", | ||
"us-east-1", | ||
"Region to create the cluster in.", | ||
) | ||
} | ||
|
||
func run(cmd *cobra.Command, argv []string) { | ||
// Create the reporter: | ||
reporter, err := rprtr.New(). | ||
Build() | ||
if err != nil { | ||
fmt.Errorf("Can't create reporter: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Check command line arguments: | ||
if len(argv) != 1 { | ||
reporter.Errorf( | ||
"Expected exactly one command line parameter containing the name " + | ||
"of the cluster", | ||
) | ||
os.Exit(1) | ||
} | ||
name := argv[0] | ||
|
||
// Check the command line options: | ||
if args.region == "" { | ||
reporter.Errorf("Option '--region' is mandatory") | ||
os.Exit(1) | ||
} | ||
|
||
// Check that there is an OCM token in the environment. This will not be needed once we are | ||
// able to derive OCM credentials from AWS credentials. | ||
ocmToken := os.Getenv("OCM_TOKEN") | ||
if ocmToken == "" { | ||
reporter.Errorf("Environment variable 'OCM_TOKEN' is not set") | ||
os.Exit(1) | ||
} | ||
|
||
// Create the logger that will be used by the OCM connection: | ||
ocmLogger, err := sdk.NewStdLoggerBuilder(). | ||
Debug(debug.Enabled()). | ||
Build() | ||
if err != nil { | ||
reporter.Errorf("Can't create OCM logger: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create the client for the OCM API: | ||
ocmConnection, err := sdk.NewConnectionBuilder(). | ||
Logger(ocmLogger). | ||
Tokens(ocmToken). | ||
URL("https://api-integration.6943.hive-integration.openshiftapps.com"). | ||
Build() | ||
if err != nil { | ||
reporter.Errorf("Can't create OCM connection: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create the permissions needed to create the cluster: | ||
reporter.Infof("Creating permissions") | ||
|
||
// Create the cluster: | ||
reporter.Infof("Creating cluster '%s'", name) | ||
ocmCluster, err := cmv1.NewCluster(). | ||
Name(name). | ||
Region( | ||
cmv1.NewCloudRegion(). | ||
ID(args.region), | ||
). | ||
Build() | ||
if err != nil { | ||
reporter.Errorf("Can't create description of OCM cluster: %v", err) | ||
os.Exit(1) | ||
} | ||
_, err = ocmConnection.ClustersMgmt().V1().Clusters().Add(). | ||
Body(ocmCluster). | ||
Send() | ||
if err != nil { | ||
reporter.Infof("Can't create OCM cluster: %v", err) | ||
os.Exit(1) | ||
} | ||
reporter.Infof("Cluster '%s' is being created", name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright (c) 2020 Red Hat, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package version | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"gitlab.cee.redhat.com/service/moactl/pkg/info" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints the version of the tool", | ||
Long: "Prints the version number of the tool.", | ||
Run: run, | ||
} | ||
|
||
func run(cmd *cobra.Command, argv []string) { | ||
fmt.Fprintf(os.Stdout, "%s\n", info.Version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module gitlab.cee.redhat.com/service/moactl | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/openshift-online/ocm-sdk-go v0.1.90 | ||
github.com/spf13/cobra v0.0.6 | ||
github.com/spf13/pflag v1.0.5 | ||
) |
Oops, something went wrong.