Add 'creator' annotation on create --force (#341)

Closes #340

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2019-08-06 16:25:55 -04:00 committed by Knative Prow Robot
parent 8e5302c741
commit 6af3edb789
1 changed files with 22 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/knative/client/pkg/kn/commands" "github.com/knative/client/pkg/kn/commands"
"github.com/knative/client/pkg/serving/v1alpha1" "github.com/knative/client/pkg/serving/v1alpha1"
"github.com/knative/serving/pkg/apis/serving"
serving_v1alpha1_api "github.com/knative/serving/pkg/apis/serving/v1alpha1" serving_v1alpha1_api "github.com/knative/serving/pkg/apis/serving/v1alpha1"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -147,6 +148,27 @@ func replaceService(client v1alpha1.KnClient, service *serving_v1alpha1_api.Serv
if err != nil { if err != nil {
return err return err
} }
// Copy over some annotations that we want to keep around. Erase others
copyList := []string{
serving.CreatorAnnotation,
serving.UpdaterAnnotation,
}
// If the target Annotation doesn't exist, create it even if
// we don't end up copying anything over so that we erase all
// existing annotations
if service.Annotations == nil {
service.Annotations = map[string]string{}
}
// Do the actual copy now, but only if it's in the source annotation
for _, k := range copyList {
if v, ok := existingService.Annotations[k]; ok {
service.Annotations[k] = v
}
}
service.ResourceVersion = existingService.ResourceVersion service.ResourceVersion = existingService.ResourceVersion
err = client.UpdateService(service) err = client.UpdateService(service)
if err != nil { if err != nil {