Skip to content
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

Go-Report-Card Fixes #30

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/shp/cmd/build/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// build contains types and functions for build cobra sub-command
// Package build contains types and functions for build cobra sub-command
package build
1 change: 1 addition & 0 deletions pkg/shp/cmd/buildrun/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/shipwright-io/cli/pkg/shp/params"
)

// Command represents "shp buildrun" sub-command.
func Command(p *params.Params, ioStreams *genericclioptions.IOStreams) *cobra.Command {
command := &cobra.Command{
Use: "buildrun",
Expand Down
2 changes: 1 addition & 1 deletion pkg/shp/cmd/buildrun/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// buildrun contains types and functions for buildrun cobra sub-command
// Package buildrun contains types and functions for buildrun cobra sub-command
package buildrun
2 changes: 1 addition & 1 deletion pkg/shp/flags/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// For instance:
//
// cmd := &cobra.Command{}
// cmd := &cobra.Command{}
// br := flags.BuildRunSpecFromFlags(cmd.Flags())
// flags.SanitizeBuildRunSpec(&br.Spec)
//
Expand Down
46 changes: 31 additions & 15 deletions pkg/shp/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,38 @@ import (
)

const (
BuildrefNameFlag = "buildref-name"
BuilderImageFlag = "builder-image"
// BuildrefNameFlag command-line flag.
BuildrefNameFlag = "buildref-name"
// BuilderImageFlag command-line flag.
BuilderImageFlag = "builder-image"
// BuilderCredentialsSecretFlag command-line flag.
BuilderCredentialsSecretFlag = "builder-credentials-secret"
DockerfileFlag = "dockerfile"
SourceURLFlag = "source-url"
SourceRevisionFlag = "source-revision"
SourceContextDirFlag = "source-context-dir"
SourceCredentialsSecretFlag = "source-credentials-secret"
StrategyAPIVersionFlag = "strategy-apiversion"
StrategyKindFlag = "strategy-kind"
StrategyNameFlag = "strategy-name"
OutputImageFlag = "output-image"
OutputCredentialsSecretFlag = "output-credentials-secret"
ServiceAccountNameFlag = "sa-name"
ServiceAccountGenerateFlag = "sa-generate"
TimeoutFlag = "timeout"
// DockerfileFlag command-line flag.
DockerfileFlag = "dockerfile"
// SourceURLFlag command-line flag.
SourceURLFlag = "source-url"
// SourceRevisionFlag command-line flag.
SourceRevisionFlag = "source-revision"
// SourceContextDirFlag command-line flag.
SourceContextDirFlag = "source-context-dir"
// SourceCredentialsSecretFlag command-line flag.
SourceCredentialsSecretFlag = "source-credentials-secret"
// StrategyAPIVersionFlag command-line flag.
StrategyAPIVersionFlag = "strategy-apiversion"
// StrategyKindFlag command-line flag.
StrategyKindFlag = "strategy-kind"
// StrategyNameFlag command-line flag.
StrategyNameFlag = "strategy-name"
// OutputImageFlag command-line flag.
OutputImageFlag = "output-image"
// OutputCredentialsSecretFlag command-line flag.
OutputCredentialsSecretFlag = "output-credentials-secret"
// ServiceAccountNameFlag command-line flag.
ServiceAccountNameFlag = "sa-name"
// ServiceAccountGenerateFlag command-line flag.
ServiceAccountGenerateFlag = "sa-generate"
// TimeoutFlag command-line flag.
TimeoutFlag = "timeout"
)

// sourceFlags flags for ".spec.source"
Expand Down
5 changes: 3 additions & 2 deletions pkg/shp/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"k8s.io/client-go/kubernetes"
)

// ShipwrightParams is a place for Shipwright CLI to store its runtime parameters
// including configured dynamic client and global flags
// Params is a place for Shipwright CLI to store its runtime parameters including configured dynamic
// client and global flags.
type Params struct {
client dynamic.Interface
clientset kubernetes.Interface
Expand Down Expand Up @@ -50,6 +50,7 @@ func (p *Params) Client() (dynamic.Interface, error) {
return p.client, nil
}

// ClientSet returns a kubernetes clientset.
func (p *Params) ClientSet() (kubernetes.Interface, error) {
if p.clientset != nil {
return p.clientset, nil
Expand Down
47 changes: 27 additions & 20 deletions pkg/shp/reactor/pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ func (p *PodWatcher) WithOnPodDeletedFn(fn OnPodEventFn) *PodWatcher {
return p
}

// handleEvent applies user informed functions against informed pod and event.
func (p *PodWatcher) handleEvent(pod *corev1.Pod, event watch.Event) error {
switch event.Type {
case watch.Added:
if p.onPodAddedFn != nil {
if err := p.onPodAddedFn(pod); err != nil {
return err
}
}
case watch.Modified:
if p.onPodModifiedFn != nil {
if err := p.onPodModifiedFn(pod); err != nil {
return err
}
}
case watch.Deleted:
if p.onPodDeletedFn != nil {
if err := p.onPodDeletedFn(pod); err != nil {
return err
}
}
}
return nil
}

// Start runs the event loop based on a watch instantiated against informed pod. In case of errors
// the loop is interrupted.
func (p *PodWatcher) Start() (*corev1.Pod, error) {
Expand All @@ -73,26 +98,8 @@ func (p *PodWatcher) Start() (*corev1.Pod, error) {
if p.skipPodFn != nil && p.skipPodFn(pod) {
continue
}

switch event.Type {
case watch.Added:
if p.onPodAddedFn != nil {
if err := p.onPodAddedFn(pod); err != nil {
return pod, err
}
}
case watch.Modified:
if p.onPodModifiedFn != nil {
if err := p.onPodModifiedFn(pod); err != nil {
return pod, err
}
}
case watch.Deleted:
if p.onPodDeletedFn != nil {
if err := p.onPodDeletedFn(pod); err != nil {
return pod, err
}
}
if err := p.handleEvent(pod, event); err != nil {
return pod, err
}
otaviof marked this conversation as resolved.
Show resolved Hide resolved
// watching over global context, when done is informed on the context it needs to reflect on
// the event loop as well.
Expand Down
7 changes: 3 additions & 4 deletions pkg/shp/resource/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// resource contains Resource type and functions for interacting with it
// it is a wrapper around kubernetes dynamic client that has
// most of the necessary type info incapsulated
// which allows us to work easier with objects stored in kubernetes
// Package resource contains Resource type and functions for interacting with it's a wrapper around
// kubernetes dynamic client that has most of the necessary type info encapsulated which allows us to
// manipulate Kubernetes objects.
package resource
2 changes: 2 additions & 0 deletions pkg/shp/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (r *Resource) Create(ctx context.Context, name string, obj interface{}) err
return util.CreateObject(ctx, ri, name, r.gv.WithKind(r.kind), obj)
}

// Update execute update against informed object.
func (r *Resource) Update(ctx context.Context, name string, obj interface{}) error {
ri, err := r.getResourceInterface()
if err != nil {
Expand Down Expand Up @@ -91,6 +92,7 @@ func (r *Resource) Get(ctx context.Context, name string, result interface{}) err
return util.GetObject(ctx, ri, name, result)
}

// Watch returns a watch for informed list options.
func (r *Resource) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
ri, err := r.getResourceInterface()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/shp/util/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func CreateObject(ctx context.Context, resource dynamic.ResourceInterface, name
return fromUnstructured(result.Object, obj)
}

// UpdateObject updates informed object reference.
func UpdateObject(ctx context.Context, resource dynamic.ResourceInterface, name string, gvk schema.GroupVersionKind, obj interface{}) error {
u, err := toUnstructured(name, gvk, obj)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/shp/util/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// util contains utility function and constants used in other packages.
// Package util contains utility function and constants used in other packages.
package util