-
Notifications
You must be signed in to change notification settings - Fork 21
[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
[client provision via catalog] create client using service catalog #128
Conversation
pkg/cmd/clients.go
Outdated
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"encoding/json" |
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.
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`, |
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.
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" |
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.
I think you can remove the following from Gopkg.toml now
[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.1.0"
pkg/cmd/clients.go
Outdated
Spec: v1alpha1.MobileClientSpec{Name: name, ApiKey: appKey, ClientType: clientType, AppIdentifier: appIdentifier}, | ||
|
||
clientId := name + "-" + clientType | ||
client, _ := cc.mobileClient.MobileV1alpha1().MobileClients(namespace).Get(clientId, metav1.GetOptions{}) |
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.
Not sure about not handling the error here, think some basic handling required at least since this calls the server
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.
we should handle the error
pkg/cmd/clients.go
Outdated
break | ||
case "xamarin": | ||
app.Annotations["icon"] = "font-icon icon-xamarin" | ||
apbName = "xamarin" |
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.
Just wondering about the formatting here why android-app
while the other types just inherit the client type, should they be ${clientType}-app
also?
pkg/cmd/clients.go
Outdated
if err != nil { | ||
return errors.Wrap(err, "failed to create mobile client") | ||
return errors.WithStack(err) |
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.
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?
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.
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
pkg/cmd/clients.go
Outdated
extMeta := clusterServiceClass.Spec.ExternalMetadata.Raw | ||
var extServiceClass ExternalServiceMetaData | ||
if err := json.Unmarshal(extMeta, &extServiceClass); err != nil { | ||
return errors.WithStack(err) |
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.
as above
pkg/cmd/clients.go
Outdated
instParams := &ServiceParams{} | ||
|
||
if err := json.Unmarshal(clusterServicePlan.Spec.ServiceInstanceCreateParameterSchema.Raw, instParams); err != nil { | ||
return errors.WithStack(err) |
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.
as above
pkg/cmd/clients.go
Outdated
return errors.WithStack(err) | ||
} | ||
|
||
si := v1beta1.ServiceInstance{ |
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.
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
pkg/cmd/clients.go
Outdated
pSecret.Data["parameters"] = secretData | ||
if _, err := cc.k8Client.CoreV1().Secrets(namespace).Create(&pSecret); err != nil { | ||
return errors.WithStack(err) | ||
} |
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.
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) | ||
} | ||
} |
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.
@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
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.
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
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.
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.
Some comments and requested changes. Not sure about the vendored changes think there might be some issues there
pkg/cmd/clients.go
Outdated
if _, err := cc.scClient.ServicecatalogV1beta1().ServiceInstances(namespace).Create(&si); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
fmt.Println("creating service") |
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.
I don't think we need this
pkg/cmd/clients.go
Outdated
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.") |
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.
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
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.
some minor changes but generally looks pretty close. Not sure why we ended up with vendor changes?
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.
@witmicko Build is failing on fmt, run go fmt -w
on touched files. Unit tests are passing, reviewing other changes now also
pkg/cmd/clients.go
Outdated
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{}) |
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.
@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") |
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.
Should this be here?
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.
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
pkg/cmd/clients_test.go
Outdated
// t.Fatal("failed to unmarshal mobile client") | ||
// } | ||
// tc.Validate(t, mobileClient) | ||
//} |
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.
I'm assuming this should be removed?
}, | ||
}, | ||
}, | ||
} |
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.
+1
pkg/cmd/clients_test.go
Outdated
"path/filepath" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"os" | ||
|
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.
Another nit on the ordering of imports here
pkg/cmd/clients_test.go
Outdated
} | ||
k8Client, mobileClient, scClient := NewClientsOrDie(config) | ||
|
||
fmt.Println(k8Client, mobileClient, scClient) |
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.
probably want this removed
pkg/cmd/clients_test.go
Outdated
func TestMobileClientsCmd_TestCreateClient(t *testing.T) { | ||
var kubeconfig *string |
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.
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.
sorry this is irrelevant, forgot to delete it, had it in as a way into debugger
e1c7e75
to
3f0d6b0
Compare
fddfdd4
to
6a4983e
Compare
6a4983e
to
302e2ba
Compare
Describe what this PR does and why we need it:
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*:
mobile create client ...
*needs:
aerogearcatalog/android-app-apb#11
aerogearcatalog/cordova-app-apb#9
aerogearcatalog/ios-app-apb#10
aerogearcatalog/xamarin-app-apb#5