-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GCP CCS command #192
GCP CCS command #192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,19 @@ limitations under the License. | |
package cluster | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"time" | ||
|
||
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
"github.com/openshift-online/ocm-cli/pkg/arguments" | ||
"github.com/openshift-online/ocm-cli/pkg/cluster" | ||
c "github.com/openshift-online/ocm-cli/pkg/cluster" | ||
"github.com/openshift-online/ocm-cli/pkg/ocm" | ||
) | ||
|
@@ -42,6 +46,7 @@ var args struct { | |
private bool | ||
multiAZ bool | ||
ccs c.CCS | ||
gcpServiceAccount arguments.FilePath | ||
|
||
// Scaling options | ||
computeMachineType string | ||
|
@@ -75,6 +80,12 @@ func init() { | |
|
||
arguments.AddProviderFlag(fs, &args.provider) | ||
arguments.AddCCSFlags(fs, &args.ccs) | ||
|
||
fs.Var( | ||
&args.gcpServiceAccount, | ||
"service-account-file", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about renaming this (BTW, maybe it's time to start using Cobra's flag groups to organize the help 🤔) |
||
"GCP service account JSON file.", | ||
) | ||
fs.StringVar( | ||
&args.region, | ||
"region", | ||
|
@@ -249,6 +260,13 @@ func run(cmd *cobra.Command, argv []string) error { | |
computeNodes = 9 | ||
} | ||
|
||
if args.gcpServiceAccount != "" { | ||
err = constructGCPCredentials(args.gcpServiceAccount, &args.ccs) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = arguments.CheckIgnoredCCSFlags(args.ccs) | ||
if err != nil { | ||
return err | ||
|
@@ -313,3 +331,19 @@ func fetchFlavours(client *cmv1.Client) (flavours []*cmv1.Flavour, err error) { | |
} | ||
return | ||
} | ||
|
||
func constructGCPCredentials(filePath arguments.FilePath, value *cluster.CCS) error { | ||
// Open our jsonFile | ||
jsonFile, err := os.Open(filePath.String()) | ||
if err != nil { | ||
return err | ||
} | ||
defer jsonFile.Close() | ||
byteValue, _ := ioutil.ReadAll(jsonFile) | ||
err = json.Unmarshal(byteValue, &value.GCP) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,33 @@ import ( | |
"reflect" | ||
"strings" | ||
|
||
"github.com/mattn/go-isatty" | ||
isatty "github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @igoihman was this deliberate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => #201 if accidental. |
||
sdk "github.com/openshift-online/ocm-sdk-go" | ||
"github.com/spf13/pflag" | ||
|
||
"github.com/openshift-online/ocm-cli/pkg/cluster" | ||
"github.com/openshift-online/ocm-cli/pkg/debug" | ||
) | ||
|
||
type FilePath string | ||
|
||
func (f *FilePath) String() string { | ||
return string(*f) | ||
} | ||
|
||
func (f *FilePath) Set(v string) error { | ||
_, err := os.Stat(v) | ||
if err != nil { | ||
return err | ||
} | ||
*f = FilePath(v) | ||
return nil | ||
} | ||
|
||
func (f *FilePath) Type() string { | ||
return "filepath" | ||
} | ||
|
||
// AddDebugFlag adds the '--debug' flag to the given set of command line flags. | ||
func AddDebugFlag(fs *pflag.FlagSet) { | ||
debug.AddFlag(fs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally declaring this flag would be part of
arguments.AddCCSFlags()
.One way to do that that might be move the FilePath var inside CCS struct, and making
constructGCPCredentials
a method on CCS struct. Don't know if worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #199 for some validations we should improve.