Skip to content

Commit

Permalink
Checkpoint. Can create trigger and source together
Browse files Browse the repository at this point in the history
  • Loading branch information
sixolet committed Dec 26, 2019
1 parent 97dd77d commit 7c71f0f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
17 changes: 9 additions & 8 deletions pkg/kn/commands/trigger/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/kn/commands/flags"
"knative.dev/client/pkg/kn/commands/source"
"knative.dev/eventing/pkg/apis/eventing/v1alpha1"
duckv1 "knative.dev/pkg/apis/duck/v1"
)
Expand Down Expand Up @@ -87,15 +86,17 @@ func NewTriggerCreateCommand(p *commands.KnParams) *cobra.Command {
URI: objectRef.URI,
}
if triggerUpdateFlags.Source != "" {
sourceCmd := source.NewSourceCommand(p)
fullSourceArgs := []string{triggerUpdateFlags.Source, "create"}
fullSourceArgs := []string{
"source", triggerUpdateFlags.Source, "create",
"--sink", fmt.Sprintf("broker:%s", triggerUpdateFlags.Broker)}
fullSourceArgs = append(fullSourceArgs, sourceArgs...)
createSource, args, err := sourceCmd.Traverse(fullSourceArgs)
if err != nil {
return err
fullSourceArgs = append(fullSourceArgs, name)
root := cmd
for root.HasParent() {
root = root.Parent()
}
fmt.Printf("SOURCE COMMAND %v\n", createSource)
err = createSource.RunE(createSource, args)
root.SetArgs(fullSourceArgs)
err = root.Execute()
if err != nil {
return err
}
Expand Down
13 changes: 2 additions & 11 deletions pkg/serving/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package serving
import (
"bytes"
"errors"
"math/rand"
"strings"
"text/template"

"knative.dev/client/pkg/util/random"
servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1"
)

Expand All @@ -42,22 +42,13 @@ func RevisionTemplateOfService(service *servingv1alpha1.Service) (*servingv1alph
return config.DeprecatedRevisionTemplate, nil
}

var charChoices = []string{
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x",
"y", "z",
}

type revisionTemplContext struct {
Service string
Generation int64
}

func (c *revisionTemplContext) Random(l int) string {
chars := make([]string, 0, l)
for i := 0; i < l; i++ {
chars = append(chars, charChoices[rand.Int()%len(charChoices)])
}
return strings.Join(chars, "")
return random.Random(l)
}

// GenerateRevisionName returns an automatically-generated name suitable for the
Expand Down
34 changes: 34 additions & 0 deletions pkg/util/random/random.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2019 The Knative Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package random

import (
"math/rand"
"strings"
)

var charChoices = []string{
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x",
"y", "z",
}

func Random(l int) string {
chars := make([]string, 0, l)
for i := 0; i < l; i++ {
chars = append(chars, charChoices[rand.Int()%len(charChoices)])
}
return strings.Join(chars, "")

}

0 comments on commit 7c71f0f

Please sign in to comment.