Skip to content
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

feat: Updating ROSA cli to use addons_mgmt apis using updated ocm-sdk-go #2547

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/create/service/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

awssdk "github.com/aws/aws-sdk-go-v2/aws"
ocmConsts "github.com/openshift-online/ocm-common/pkg/ocm/consts"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand Down Expand Up @@ -200,7 +200,7 @@ func run(cmd *cobra.Command, argv []string) {
if parameters.Len() > 0 {
args.Parameters = map[string]string{}
// Determine if all required parameters have already been set as flags.
parameters.Each(func(param *cmv1.AddOnParameter) bool {
parameters.Each(func(param *asv1.AddonParameter) bool {
flag := cmd.Flags().Lookup(param.ID())
if param.Required() && (flag == nil || flag.Value.String() == "") {
r.Reporter.Errorf("Required parameter --%s missing", param.ID())
Expand Down
10 changes: 5 additions & 5 deletions cmd/describe/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"regexp"
"strings"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
"github.com/spf13/cobra"

"github.com/openshift/rosa/pkg/rosa"
Expand Down Expand Up @@ -65,7 +65,7 @@ func run(_ *cobra.Command, argv []string) {
printParameters(addOn.Parameters())
}

func printDescription(addOn *cmv1.AddOn) {
func printDescription(addOn *asv1.Addon) {
fmt.Printf("ADD-ON\n"+
"ID: %s\n"+
"Name: %s\n"+
Expand All @@ -85,7 +85,7 @@ func printDescription(addOn *cmv1.AddOn) {
fmt.Println()
}

func printCredentialRequests(requests []*cmv1.CredentialRequest) {
func printCredentialRequests(requests []*asv1.CredentialRequest) {
if len(requests) > 0 {
fmt.Printf("CREDENTIALS REQUESTS\n")
for _, cr := range requests {
Expand All @@ -108,10 +108,10 @@ func printCredentialRequests(requests []*cmv1.CredentialRequest) {
fmt.Println()
}

func printParameters(params *cmv1.AddOnParameterList) {
func printParameters(params *asv1.AddonParameterList) {
if params.Len() > 0 {
fmt.Printf("ADD-ON PARAMETERS\n")
params.Each(func(param *cmv1.AddOnParameter) bool {
params.Each(func(param *asv1.AddonParameter) bool {
if !param.Enabled() {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/describe/installation/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"os"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
"github.com/spf13/cobra"

"github.com/openshift/rosa/pkg/ocm"
Expand Down Expand Up @@ -106,8 +106,8 @@ func describeAddonInstallation(r *rosa.Runtime, installationKey string) error {
if parameters.Len() > 0 {
fmt.Println("Parameters:")
}
parameters.Each(func(parameter *cmv1.AddOnInstallationParameter) bool {
fmt.Printf("\t%-28q: %q\n", parameter.ID(), parameter.Value())
parameters.Each(func(parameter *asv1.AddonInstallationParameter) bool {
fmt.Printf("\t%-28q: %q\n", parameter.Id(), parameter.Value())
return true
})

Expand Down
11 changes: 6 additions & 5 deletions cmd/edit/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"regexp"
"strings"

asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -101,7 +102,7 @@ func run(cmd *cobra.Command, argv []string) {
// set as flags, then we also ensure that interactive mode is enabled so that the
// user gets prompted.
if arguments.HasUnknownFlags() {
addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
flag := cmd.Flags().Lookup(param.ID())
if flag != nil && !param.Editable() {
r.Reporter.Errorf("Parameter '%s' on addon '%s' cannot be modified", param.ID(), addOnID)
Expand All @@ -114,11 +115,11 @@ func run(cmd *cobra.Command, argv []string) {
}

var addonArguments []ocm.AddOnParam
addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
// Find the installation parameter corresponding to the addon parameter
var addOnInstallationParam *cmv1.AddOnInstallationParameter
addOnInstallation.Parameters().Each(func(p *cmv1.AddOnInstallationParameter) bool {
if p.ID() == param.ID() {
var addOnInstallationParam *asv1.AddonInstallationParameter
addOnInstallation.Parameters().Each(func(p *asv1.AddonInstallationParameter) bool {
if p.Id() == param.ID() {
addOnInstallationParam = p
return false
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/edit/service/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package service
import (
"os"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
"github.com/spf13/cobra"

"github.com/openshift/rosa/pkg/arguments"
Expand Down Expand Up @@ -84,7 +84,7 @@ func run(cmd *cobra.Command, argv []string) {
}

addonParameters := addOn.Parameters()
addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
arguments.AddStringFlag(cmd, param.ID())
return true
})
Expand All @@ -96,7 +96,7 @@ func run(cmd *cobra.Command, argv []string) {
}

args.Parameters = map[string]string{}
addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
flag := cmd.Flags().Lookup(param.ID())
// Checking if the flag changed to ensure that the user set the value.
if flag != nil && flag.Changed {
Expand Down
9 changes: 5 additions & 4 deletions cmd/install/addon/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
awserr "github.com/openshift-online/ocm-common/pkg/aws/errors"
awsCommonUtils "github.com/openshift-online/ocm-common/pkg/aws/utils"
amv1 "github.com/openshift-online/ocm-sdk-go/accountsmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/spf13/cobra"
errors "github.com/zgalor/weberr"
Expand Down Expand Up @@ -180,7 +181,7 @@ func run(cmd *cobra.Command, argv []string) {
// set as flags, then we also ensure that interactive mode is enabled so that the
// user gets prompted.
if arguments.HasUnknownFlags() {
addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
flag := cmd.Flags().Lookup(param.ID())
if param.Required() && (flag == nil || flag.Value.String() == "") {
interactive.Enable()
Expand All @@ -192,7 +193,7 @@ func run(cmd *cobra.Command, argv []string) {
interactive.Enable()
}

addonParameters.Each(func(param *cmv1.AddOnParameter) bool {
addonParameters.Each(func(param *asv1.AddonParameter) bool {
var val string
var options []string
var values []string
Expand Down Expand Up @@ -297,7 +298,7 @@ func ensureAddonNotInstalled(r *rosa.Runtime, clusterID, addOnID string) {
}
}

func createAddonRole(r *rosa.Runtime, roleName string, cr *cmv1.CredentialRequest, cmd *cobra.Command,
func createAddonRole(r *rosa.Runtime, roleName string, cr *asv1.CredentialRequest, cmd *cobra.Command,
cluster *cmv1.Cluster) error {
policy := aws.NewPolicyDocument()
policy.AllowActions(cr.PolicyPermissions()...)
Expand Down Expand Up @@ -354,7 +355,7 @@ func buildCommand(
return command
}

func generateRoleName(cr *cmv1.CredentialRequest, prefix string) string {
func generateRoleName(cr *asv1.CredentialRequest, prefix string) string {
roleName := fmt.Sprintf("%s-%s-%s", prefix, cr.Namespace(), cr.Name())
return awsCommonUtils.TruncateRoleName(roleName)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ require (
)

replace github.com/golang/glog => github.com/kubermatic/glog-logrus v0.0.0-20180829085450-3fa5b9870d1d

replace github.com/openshift-online/ocm-sdk-go => github.com/venkateshsredhat/ocm-sdk-go v0.1.445-newtest
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openshift-online/ocm-common v0.0.12 h1:2oGZCXd8O/nZVlM0pvTtm3hDGbW/ncTtvSLLB+nuQf0=
github.com/openshift-online/ocm-common v0.0.12/go.mod h1:6MWje2NFNJ3IWpGs7BYj6DWagWXHyp8EnmYY7XFTtI4=
github.com/openshift-online/ocm-sdk-go v0.1.440 h1:qHVF8iZ0V3DPPuZq2LF7pwQKVsm0W0QxVDoXxDS7oyw=
github.com/openshift-online/ocm-sdk-go v0.1.440/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -328,6 +326,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/venkateshsredhat/ocm-sdk-go v0.1.445-newtest h1:nrbq5o2IFkMtUVgxbE+GC6ZgKxXDEfVubja/eXnR+OQ=
github.com/venkateshsredhat/ocm-sdk-go v0.1.445-newtest/go.mod h1:CiAu2jwl3ITKOxkeV0Qnhzv4gs35AmpIzVABQLtcI2Y=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
3 changes: 2 additions & 1 deletion pkg/aws/policy_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iam"
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
)

Expand Down Expand Up @@ -314,7 +315,7 @@ func GenerateOperatorRolePolicyDoc(partition string, cluster *cmv1.Cluster,
accountID, operator, policyDetails)
}

func GenerateAddonPolicyDoc(partition string, cluster *cmv1.Cluster, accountID string, cr *cmv1.CredentialRequest,
func GenerateAddonPolicyDoc(partition string, cluster *cmv1.Cluster, accountID string, cr *asv1.CredentialRequest,
policyDetails string) (string, error) {
service_accounts := fmt.Sprintf("system:serviceaccount:%s:%s", cr.Namespace(), cr.ServiceAccount())
return GenerateRolePolicyDoc(partition, cluster.AWS().STS().OIDCEndpointURL(),
Expand Down
6 changes: 3 additions & 3 deletions pkg/interactive/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strconv"
"strings"

cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
asv1 "github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1"
)

func GetAddonArgument(param cmv1.AddOnParameter, dflt string) (string, error) {
func GetAddonArgument(param asv1.AddonParameter, dflt string) (string, error) {
var input = Input{
Question: param.Name(),
Help: fmt.Sprintf("%s: %s", param.ID(), param.Description()),
Expand Down Expand Up @@ -109,7 +109,7 @@ func GetAddonArgument(param cmv1.AddOnParameter, dflt string) (string, error) {
return "", fmt.Errorf("The parameter '%s' does not support interactive mode", param.ID())
}

func getOptionNames(param cmv1.AddOnParameter) []string {
func getOptionNames(param asv1.AddonParameter) []string {
var optionNames []string
options, _ := param.GetOptions()
for _, option := range options {
Expand Down
Loading