mirror of https://github.com/knative/client.git
Checks if --image is given before applying image to config (#118)
Fixes #117
This commit is contained in:
parent
8bb85c6aed
commit
bbfc9fbaa3
|
|
@ -54,7 +54,7 @@ func (p *ConfigurationEditFlags) AddCreateFlags(command *cobra.Command) {
|
|||
command.MarkFlagRequired("image")
|
||||
}
|
||||
|
||||
func (p *ConfigurationEditFlags) Apply(config *servingv1alpha1.ConfigurationSpec) error {
|
||||
func (p *ConfigurationEditFlags) Apply(config *servingv1alpha1.ConfigurationSpec, cmd *cobra.Command) error {
|
||||
envMap := map[string]string{}
|
||||
for _, pairStr := range p.Env {
|
||||
pairSlice := strings.SplitN(pairStr, "=", 2)
|
||||
|
|
@ -69,9 +69,11 @@ func (p *ConfigurationEditFlags) Apply(config *servingv1alpha1.ConfigurationSpec
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = servinglib.UpdateImage(config, p.Image)
|
||||
if err != nil {
|
||||
return err
|
||||
if cmd.Flags().Changed("image") {
|
||||
err = servinglib.UpdateImage(config, p.Image)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
limitsResources, err := p.computeResources(p.LimitsFlags)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func NewServiceCreateCommand(p *KnParams) *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = editFlags.Apply(config)
|
||||
err = editFlags.Apply(config, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func NewServiceUpdateCommand(p *KnParams) *cobra.Command {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = editFlags.Apply(config)
|
||||
err = editFlags.Apply(config, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,51 @@ func TestServiceUpdateImage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceUpdateEnv(t *testing.T) {
|
||||
orig := &v1alpha1.Service{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Service",
|
||||
APIVersion: "knative.dev/v1alpha1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1alpha1.ServiceSpec{
|
||||
RunLatest: &v1alpha1.RunLatestType{},
|
||||
},
|
||||
}
|
||||
|
||||
config, err := servinglib.GetConfiguration(orig)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
servinglib.UpdateImage(config, "gcr.io/foo/bar:baz")
|
||||
|
||||
action, updated, _, err := fakeServiceUpdate(orig, []string{
|
||||
"service", "update", "foo", "-e", "TARGET=Awesome"})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !action.Matches("update", "services") {
|
||||
t.Fatalf("Bad action %v", action)
|
||||
}
|
||||
expectedEnvVar := corev1.EnvVar{
|
||||
Name: "TARGET",
|
||||
Value: "Awesome",
|
||||
}
|
||||
|
||||
conf, err := servinglib.GetConfiguration(updated)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if conf.RevisionTemplate.Spec.Container.Image != "gcr.io/foo/bar:baz" {
|
||||
t.Fatalf("wrong image set: %v", conf.RevisionTemplate.Spec.Container.Image)
|
||||
} else if conf.RevisionTemplate.Spec.Container.Env[0] != expectedEnvVar {
|
||||
t.Fatalf("wrong env set: %v", conf.RevisionTemplate.Spec.Container.Env)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceUpdateRequestsLimitsCPU(t *testing.T) {
|
||||
service := createMockServiceWithResources(t, "250", "64Mi", "1000m", "1024Mi")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue