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

Add SkaffoldLogEvents for pod updates #6358

Merged
merged 6 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
tejal29 committed Aug 4, 2021
commit c533e7ca101ead83d4c5161041f3bfc1d6b38d31
2 changes: 1 addition & 1 deletion examples/getting-started/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func main() {
for {
fmt.Println("Hello world!")

time.Sleep(time.Hour * 1)
time.Sleep(time.Second * 1)
}
}
9 changes: 3 additions & 6 deletions pkg/skaffold/build/cluster/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"io/ioutil"

"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
typedV1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand All @@ -36,7 +37,6 @@ const (
)

func (b *Builder) setupPullSecret(ctx context.Context, out io.Writer) (func(), error) {
logrus := output.GetLogger(out)
if b.PullSecretPath == "" && b.PullSecretName == "" {
return func() {}, nil
}
Expand All @@ -53,7 +53,7 @@ func (b *Builder) setupPullSecret(ctx context.Context, out io.Writer) (func(), e
if b.PullSecretPath == "" {
return nil, fmt.Errorf("secret %s does not exist. No path specified to create it", b.PullSecretName)
}
return b.createSecretFromFile(ctx, out, secrets)
return b.createSecretFromFile(ctx, secrets)
}
if b.PullSecretPath == "" {
// TODO: Remove the warning when pod health check can display pod failure errors.
Expand All @@ -64,7 +64,7 @@ func (b *Builder) setupPullSecret(ctx context.Context, out io.Writer) (func(), e
return func() {}, nil
}

func (b *Builder) createSecretFromFile(ctx context.Context, out io.Writer, secrets typedV1.SecretInterface) (func(), error) {
func (b *Builder) createSecretFromFile(ctx context.Context, secrets typedV1.SecretInterface) (func(), error) {
secretData, err := ioutil.ReadFile(b.PullSecretPath)
if err != nil {
return nil, fmt.Errorf("cannot create secret %s from path %s. reading pull secret: %w", b.PullSecretName, b.PullSecretPath, err)
Expand All @@ -85,14 +85,12 @@ func (b *Builder) createSecretFromFile(ctx context.Context, out io.Writer, secre

return func() {
if err := secrets.Delete(ctx, b.PullSecretName, metav1.DeleteOptions{}); err != nil {
logrus := output.GetLogger(out)
logrus.Warnf("deleting pull secret")
}
}, nil
}

func (b *Builder) setupDockerConfigSecret(ctx context.Context, out io.Writer) (func(), error) {
logrus := output.GetLogger(out)
if b.DockerConfig == nil {
return func() {}, nil
}
Expand Down Expand Up @@ -137,7 +135,6 @@ func (b *Builder) setupDockerConfigSecret(ctx context.Context, out io.Writer) (f

return func() {
if err := secrets.Delete(ctx, b.DockerConfig.SecretName, metav1.DeleteOptions{}); err != nil {
logrus := output.GetLogger(out)
logrus.Warnf("deleting docker config secret")
}
}, nil
Expand Down
3 changes: 0 additions & 3 deletions pkg/skaffold/build/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"strconv"

"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
Expand Down Expand Up @@ -142,8 +141,6 @@ func InOrder(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts [

func performBuild(ctx context.Context, cw io.Writer, tags tag.ImageTags, artifact *latestV1.Artifact, build ArtifactBuilder) (string, error) {
output.Default.Fprintf(cw, "Building [%s]...\n", artifact.ImageName)
logrus.Infoln("Building using %s", artifact.ArtifactType)
panic("forced.....")
tag, present := tags[artifact.ImageName]
if !present {
return "", fmt.Errorf("unable to find tag for image %s", artifact.ImageName)
Expand Down
6 changes: 1 addition & 5 deletions pkg/skaffold/event/v2/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@ func (h logHook) Levels() []logrus.Level {

// Fire constructs a SkaffoldLogEvent and sends it to the event channel
func (h logHook) Fire(entry *logrus.Entry) error {
taskId := "-1"
if v, ok := entry.Data["subtaskID"]; ok {
taskId = v.(string)
}
handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{
TaskId: fmt.Sprintf("%s-%d", h.task, handler.iteration),
SubtaskId: taskId,
SubtaskId: h.subtask,
Level: levelFromEntry(entry),
Message: entry.Message,
})
Expand Down
36 changes: 24 additions & 12 deletions pkg/skaffold/event/v2/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ import (
proto "github.com/GoogleContainerTools/skaffold/proto/v2"
)

func ResourceStatusCheckEventCompleted(r string, ae proto.ActionableErr) {
//func ResourceStatusCheckEventCompleted(r string, ae proto.ActionableErr) {
// if ae.ErrCode != proto.StatusCode_STATUSCHECK_SUCCESS {
// resourceStatusCheckEventFailed(r, ae)
// return
// }
// resourceStatusCheckEventSucceeded(r)
//}

func ResourceStatusCheckEventCompleted(r string, message string, ae proto.ActionableErr) {
if ae.ErrCode != proto.StatusCode_STATUSCHECK_SUCCESS {
resourceStatusCheckEventFailed(r, ae)
return
}
resourceStatusCheckEventSucceeded(r)
}

func ResourceStatusCheckEventCompletedWithLog(r string, ae proto.ActionableErr) {
ResourceStatusCheckEventCompleted(r, ae)
handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{
TaskId: fmt.Sprintf("%s-%d", constants.Deploy, handler.iteration),
SubtaskId: r,
Message: ae.Message,
Message: message,
})
}

Expand All @@ -62,7 +66,19 @@ func resourceStatusCheckEventFailed(r string, ae proto.ActionableErr) {
})
}

func ResourceStatusCheckEventUpdated(r string, ae proto.ActionableErr) {
//func ResourceStatusCheckEventUpdated(r string, ae proto.ActionableErr) {
// handler.handleStatusCheckSubtaskEvent(&proto.StatusCheckSubtaskEvent{
// Id: r,
// TaskId: fmt.Sprintf("%s-%d", constants.Deploy, handler.iteration),
// Resource: r,
// Status: InProgress,
// Message: ae.Message,
// StatusCode: ae.ErrCode,
// ActionableErr: &ae,
// })
//}

func ResourceStatusCheckEventUpdated(r string, message string, ae proto.ActionableErr) {
handler.handleStatusCheckSubtaskEvent(&proto.StatusCheckSubtaskEvent{
Id: r,
TaskId: fmt.Sprintf("%s-%d", constants.Deploy, handler.iteration),
Expand All @@ -72,14 +88,10 @@ func ResourceStatusCheckEventUpdated(r string, ae proto.ActionableErr) {
StatusCode: ae.ErrCode,
ActionableErr: &ae,
})
}

func ResourceStatusCheckEventUpdatedWithLog(r string, ae proto.ActionableErr) {
ResourceStatusCheckEventUpdated(r, ae)
handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{
TaskId: fmt.Sprintf("%s-%d", constants.Deploy, handler.iteration),
SubtaskId: r,
Message: ae.Message,
Message: fmt.Sprintf("%s %s", message, ae.Message),
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/event/v2/status_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestResourceStatusCheckEventUpdated(t *testing.T) {
handler.state = emptyState(mockCfg([]latestV1.Pipeline{{}}, "test"))

wait(t, func() bool { return handler.getState().StatusCheckState.Status == NotStarted })
ResourceStatusCheckEventUpdated("ns:pod/foo", proto.ActionableErr{
ResourceStatusCheckEventUpdated("ns:pod/foo", "", proto.ActionableErr{
ErrCode: 509,
Message: "image pull error",
})
Expand Down
Loading