8000 [client provision via catalog] create client using service catalog by witmicko · Pull Request #128 · aerogear-attic/mobile-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[client provision via catalog] create client using service catalog #128

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

Merged
merged 6 commits into from
Jun 18, 2018

Conversation

witmicko
Copy link
Contributor
@witmicko witmicko commented Jun 12, 2018

Describe what this PR does and why we need it:

  • provision via catalog
  • unit test

Does this PR depend on another PR (Use this to track when PRs should be merged)
aerogearcatalog/android-app-apb#11

Which issue this PR fixes (This will close that issue when PR gets merged)
https://issues.jboss.org/browse/AEROGEAR-3023

Verification steps*:

  1. pull this changes and build binary
  2. run different variants of mobile create client ...
  3. ensure that each mobile client has corresponding service instance
  4. MAR view annotated service_instance_id should match service instance id

*needs:
aerogearcatalog/android-app-apb#11
aerogearcatalog/cordova-app-apb#9
aerogearcatalog/ios-app-apb#10
aerogearcatalog/xamarin-app-apb#5

8000
@witmicko witmicko requested a review from maleck13 June 12, 2018 16:32
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"encoding/json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its good practice to list imports from stdlib first followed by external dependencies but this is just a nit.

kubectl plugin mobile get clients
oc plugin mobile get clients`,
kubectl plugin mobile get clients
oc plugin mobile get clients`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation is preferred I would say but I'd suggest change others to this format for consistency since we are touching the file here anyway

name = "github.com/satori/go.uuid"
packages = ["."]
revision = "879c5887cd475cd7864858769793b2ceb0d44feb"
version = "v1.1.0"
Copy link
Contributor
@philipgough philipgough Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the following from Gopkg.toml now

[[constraint]]
  name = "github.com/satori/go.uuid"
  version = "1.1.0"

Spec: v1alpha1.MobileClientSpec{Name: name, ApiKey: appKey, ClientType: clientType, AppIdentifier: appIdentifier},

clientId := name + "-" + clientType
client, _ := cc.mobileClient.MobileV1alpha1().MobileClients(namespace).Get(clientId, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about not handling the error here, think some basic handling required at least since this calls the server

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should handle the error

break
case "xamarin":
app.Annotations["icon"] = "font-icon icon-xamarin"
apbName = "xamarin"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering about the formatting here why android-app while the other types just inherit the client type, should they be ${clientType}-app also?

if err != nil {
return errors.Wrap(err, "failed to create mobile client")
return errors.WithStack(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to wrap this and the above error like with the previous. I feel we are exposing more than needed to the caller here, wdyt?

Copy link
Contributor
@maleck13 maleck13 Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob depends what we are logging also. I think the stack trace only shows if we use "%+v". As a general point though I prefer having the context added to the err as the err can be obscure sometimes

extMeta := clusterServiceClass.Spec.ExternalMetadata.Raw
var extServiceClass ExternalServiceMetaData
if err := json.Unmarshal(extMeta, &extServiceClass); err != nil {
return errors.WithStack(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

instParams := &ServiceParams{}

if err := json.Unmarshal(clusterServicePlan.Spec.ServiceInstanceCreateParameterSchema.Raw, instParams); err != nil {
return errors.WithStack(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

return errors.WithStack(err)
}

si := v1beta1.ServiceInstance{
Copy link
Contributor
@philipgough philipgough Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this might be better as a call to a constructor. I see similar creation in same pkg in at least one place https://github.com/aerogear/mobile-cli/blob/master/pkg/cmd/services.go#L231 have not checked for more but do you think it makes sense to move this out?

I havent looked too deeply into so ignore if it complicates things or provides no warranted dryness

pSecret.Data["parameters"] = secretData
if _, err := cc.k8Client.CoreV1().Secrets(namespace).Create(&pSecret); err != nil {
return errors.WithStack(err)
}
Copy link
Contributor
@philipgough philipgough Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably arrange the above like

			parameters := map[string]string{
				"appName": name,
				"appIdentifier": appIdentifier,
			}
			secretData, err := json.Marshal(parameters)
			if err != nil {
				return errors.WithStack(err)
			}

			pSecret := v1.Secret{
				ObjectMeta: metav1.ObjectMeta{
					Name: clientId + "-apb-" + "params",
				},
				Data: map[string][]byte{
					"parameters": secretData,
				},
			}

we could fail early this way but its personal preferece, existing code is fine except for the above comments in regards to error wrapping

w.Stop()
return errors.New("Failed to provision " + extServiceClass.ServiceName + ". " + c.Message)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@witmicko I' unsure about this behaviour because it doesn't seem consistent with other cli behaviour from oc or kubectl. IMO the request should just end with error or ok if the server was happy to accept and the user can initiate a watch later if they wish but there may be reasons for the above, dont have enough context to say if this should be removed or remain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this for other services and allow a --no-wait flag to be passed. So I think this is ok for now. It may be something we want to change where no-wait is the default and you can pass an option to wait. But not something for this issue I think

Copy link
Contributor
@philipgough philipgough Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do this for other services

@witmicko, @maleck13 Cool, fine with this then if its consistent with others but I was coming from the angle where we would go something like oc get pods -w to initiate a watch after a request

Copy link
Contributor
@philipgough philipgough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments and requested changes. Not sure about the vendored changes think there might be some issues there

if _, err := cc.scClient.ServicecatalogV1beta1().ServiceInstances(namespace).Create(&si); err != nil {
return errors.WithStack(err)
}
fmt.Println("creating service")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this

select {
case msg, ok := <-w.ResultChan():
if !ok {
fmt.Println("Timedout waiting. It seems to be taking a long time for the service to provision. Your service may still be provisioning.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this error call less about a service (I know we are provisioning a service instance) and say timedout creating the mobile client

Copy link
Contributor
@maleck13 maleck13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor changes but generally looks pretty close. Not sure why we ended up with vendor changes?

Copy link
Contributor
@philipgough philipgough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@witmicko Build is failing on fmt, run go fmt -w on touched files. Unit tests are passing, reviewing other changes now also

cc.Out.AddRenderer("create"+cmd.Name(), "table", func(writer io.Writer, mobileClient interface{}) error {
mClient := mobileClient.(*v1alpha1.MobileClient)
mClient, _ := cc.mobileClient.MobileV1alpha1().MobileClients(namespace).Get(clientId, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@witmicko We should handle the error here also

outType := outputType(cmd.Flags())
if err := cc.Out.Render("create"+cmd.Name(), outType, createdClient); err != nil {
return errors.Wrap(err, fmt.Sprintf(output.FailedToOutPutInFormat, "mobile client", outType))
fmt.Println("Creating Mobile Client")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it takes a while to provision, so I followed the pattern from creating service instance and log it out to let the user know what is happening

// t.Fatal("failed to unmarshal mobile client")
// }
// tc.Validate(t, mobileClient)
//}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this should be removed?

},
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

"path/filepath"
"k8s.io/client-go/tools/clientcmd"
"os"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nit on the ordering of imports here

}
k8Client, mobileClient, scClient := NewClientsOrDie(config)

fmt.Println(k8Client, mobileClient, scClient)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want this removed

func TestMobileClientsCmd_TestCreateClient(t *testing.T) {
var kubeconfig *string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maleck13 @witmicko I'm trying to wrap my head around these tests but in this particular test I think we are creating a real client and I don't see us doing that anywhere else, any reason why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry this is irrelevant, forgot to delete it, had it in as a way into debugger

@witmicko witmicko force-pushed the client-create-catalog branch from e1c7e75 to 3f0d6b0 Compare June 14, 2018 13:16
@philipgough philipgough force-pushed the client-create-catalog branch 2 times, most recently from fddfdd4 to 6a4983e Compare June 15, 2018 10:47
@philipgough philipgough force-pushed the client-create-catalog branch from 6a4983e to 302e2ba Compare June 15, 2018 12:19
@witmicko witmicko merged commit b5867b6 into aerogear-attic:master Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0