Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…fold into metadata
  • Loading branch information
MarlonGamez committed Jun 1, 2021
2 parents feccf31 + f477f48 commit 46a7610
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 214 deletions.
27 changes: 8 additions & 19 deletions deploy/setup-secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,14 @@ while getopts "p:" opt; do
esac
done

VALID_KEYS=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID} --managed-by=user --filter="validBeforeTime.date('%Y-%m-%d', Z)>`date +%F`" --format="value(name)")

# create a new valid key
gcloud iam service-accounts keys create ${KEY_FILE} --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID}
retVal=$?
if [ $retVal -ne 0 ]; then
echo "No permissions to list keys."
exit 1
echo "No key created."
exit 1
fi

if [ -z "$VALID_KEYS" ]; then
# create a new valid key
gcloud iam service-accounts keys create ${KEY_FILE} --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID}
retVal=$?
if [ $retVal -ne 0 ]; then
echo "No key created."
exit 1
fi
KEY_ID=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@${PROJECT_ID}.iam.gserviceaccount.com --project=${PROJECT_ID} --managed-by=user --filter="validBeforeTime.date('%Y-%m-%d', Z)>`date +%F`" --format="value(name)")
gsutil cp ${KEY_FILE} gs://${BUCKET_ID}/${KEY_ID}.json
gsutil cp ${KEY_FILE} gs://${BUCKET_ID}/${LATEST_GCS_PATH}
else
# download the valid key from gcs
gsutil cp gs://${BUCKET_ID}/${LATEST_GCS_PATH} ${KEY_FILE}
fi
KEY_ID=$(gcloud iam service-accounts keys list --iam-account=metrics-writer@k8s-skaffold.iam.gserviceaccount.com --project=k8s-skaffold --managed-by=user --filter="validAfterTime.date('%Y-%m-%d', Z) = `date +%F`" --format="value(name)" --limit=1)
gsutil cp ${KEY_FILE} gs://${BUCKET_ID}/${KEY_ID}.json
gsutil cp ${KEY_FILE} gs://${BUCKET_ID}/${LATEST_GCS_PATH}
14 changes: 12 additions & 2 deletions docs/content/en/docs/workflows/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ a debug launcher that examines the app command-line.

#### .NET Core (runtime: `dotnet`, protocols: `vsdbg`)

.NET Core applications are configured to be deployed along with `vsdbg`.
.NET Core applications are configured to be deployed along with `vsdbg`
for VS Code.


.NET Core application are recognized by:
- the presence of a standard .NET environment variable:
Expand All @@ -237,7 +239,14 @@ a debug launcher that examines the app command-line.

Furthermore, your app must be built with the `--configuration Debug` options to disable optimizations.

**Note for users of [VS Code's debug adapter for C#](https://github.com/OmniSharp/omnisharp-vscode):**

{{< alert title="JetBrains Rider" >}}
This set up does not yet work automatically with [Cloud Code for IntelliJ in JetBrains Rider](https://github.com/GoogleCloudPlatform/cloud-code-intellij/issues/2903).
There is [a manual workaround](https://github.com/GoogleCloudPlatform/cloud-code-intellij/wiki/Manual-set-up-for-remote-debugging-in-Rider).
{{< /alert >}}

{{< alert title="Omnisharp for VS Code" >}}
For users of [VS Code's debug adapter for C#](https://github.com/OmniSharp/omnisharp-vscode):**
the following configuration can be used to debug a container. It assumes that your code is deployed
in `/app` or `/src` folder in the container. If that is not the case, the `sourceFileMap` property
should be changed to match the correct folder. `processId` is usually 1 but might be different if you
Expand Down Expand Up @@ -272,6 +281,7 @@ your base image. (`//` comments must be stripped.)
}
}
```
{{< /alert >}}

## Troubleshooting

Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/build/cache/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output"
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
Expand Down Expand Up @@ -56,6 +57,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
var needToBuild []*latestV1.Artifact
var alreadyBuilt []graph.Artifact
for i, artifact := range artifacts {
eventV2.CacheCheckInProgress(artifact.ImageName)
output.Default.Fprintf(out, " - %s: ", artifact.ImageName)

result := results[i]
Expand All @@ -65,24 +67,28 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
return nil, result.err

case needsBuilding:
eventV2.CacheCheckMiss(artifact.ImageName)
output.Yellow.Fprintln(out, "Not found. Building")
hashByName[artifact.ImageName] = result.Hash()
needToBuild = append(needToBuild, artifact)
continue

case needsTagging:
eventV2.CacheCheckHit(artifact.ImageName)
output.Green.Fprintln(out, "Found. Tagging")
if err := result.Tag(ctx, c); err != nil {
return nil, fmt.Errorf("tagging image: %w", err)
}

case needsPushing:
eventV2.CacheCheckHit(artifact.ImageName)
output.Green.Fprintln(out, "Found. Pushing")
if err := result.Push(ctx, out, c); err != nil {
return nil, fmt.Errorf("%s: %w", sErrors.PushImageErr, err)
}

default:
eventV2.CacheCheckHit(artifact.ImageName)
isLocal, err := c.isLocalImage(artifact.ImageName)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/skaffold/build/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@ func (s *scheduler) build(ctx context.Context, tags tag.ImageTags, i int) error
defer release()

event.BuildInProgress(a.ImageName)
eventV2.BuildInProgress(i, a.ImageName)
eventV2.BuildInProgress(a.ImageName)

w, closeFn, err := s.logger.GetWriter()
if err != nil {
event.BuildFailed(a.ImageName, err)
eventV2.BuildFailed(i, a.ImageName, err)
eventV2.BuildFailed(a.ImageName, err)
return err
}
defer closeFn()

finalTag, err := performBuild(ctx, w, tags, a, s.artifactBuilder)
if err != nil {
event.BuildFailed(a.ImageName, err)
eventV2.BuildFailed(i, a.ImageName, err)
eventV2.BuildFailed(a.ImageName, err)
return err
}

s.results.Record(a, finalTag)
n.markComplete()
event.BuildComplete(a.ImageName)
eventV2.BuildSucceeded(i, a.ImageName)
eventV2.BuildSucceeded(a.ImageName)
return nil
}

Expand Down
41 changes: 33 additions & 8 deletions pkg/skaffold/deploy/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,18 @@ var testDeploySkipBuildDependencies = latestV1.HelmDeploy{

var testDeployRemoteChart = latestV1.HelmDeploy{
Releases: []latestV1.HelmRelease{{
Name: "skaffold-helm-remote",
ChartPath: "stable/chartmuseum",
SkipBuildDependencies: false,
Name: "skaffold-helm-remote",
RemoteChart: "stable/chartmuseum",
Repo: "https://charts.helm.sh/stable",
}},
}

var testDeployRemoteChartVersion = latestV1.HelmDeploy{
Releases: []latestV1.HelmRelease{{
Name: "skaffold-helm-remote",
RemoteChart: "stable/chartmuseum",
Version: "1.0.0",
Repo: "https://charts.helm.sh/stable",
}},
}

Expand Down Expand Up @@ -491,7 +500,6 @@ func TestHelmDeploy(t *testing.T) {
expectedWarnings []string
expectedNamespaces []string
}{

{
description: "helm3.0beta deploy success",
commands: testutil.
Expand Down Expand Up @@ -693,13 +701,30 @@ func TestHelmDeploy(t *testing.T) {
helm: testDeployUpgradeOnChange,
},
{
description: "deploy error remote chart without skipBuildDependencies",
description: "deploy remote chart",
commands: testutil.
CmdRunWithOutput("helm version --client", version31).
AndRunErr("helm --kube-context kubecontext get all skaffold-helm-remote --kubeconfig kubeconfig", fmt.Errorf("Error: release: not found")).
AndRun("helm --kube-context kubecontext install skaffold-helm-remote stable/chartmuseum --repo https://charts.helm.sh/stable --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext get all skaffold-helm-remote --template {{.Release.Manifest}} --kubeconfig kubeconfig"),
helm: testDeployRemoteChart,
},
{
description: "deploy remote chart with version",
commands: testutil.
CmdRunWithOutput("helm version --client", version31).
AndRun("helm --kube-context kubecontext get all skaffold-helm-remote --kubeconfig kubeconfig").
AndRunErr("helm --kube-context kubecontext dep build stable/chartmuseum --kubeconfig kubeconfig", fmt.Errorf("building helm dependencies")),
AndRunErr("helm --kube-context kubecontext get all skaffold-helm-remote --kubeconfig kubeconfig", fmt.Errorf("Error: release: not found")).
AndRun("helm --kube-context kubecontext install skaffold-helm-remote --version 1.0.0 stable/chartmuseum --repo https://charts.helm.sh/stable --kubeconfig kubeconfig").
AndRun("helm --kube-context kubecontext get all skaffold-helm-remote --template {{.Release.Manifest}} --kubeconfig kubeconfig"),
helm: testDeployRemoteChartVersion,
},
{
description: "deploy error with remote chart",
commands: testutil.
CmdRunWithOutput("helm version --client", version31).
AndRunErr("helm --kube-context kubecontext get all skaffold-helm-remote --kubeconfig kubeconfig", fmt.Errorf("Error: release: not found")).
AndRunErr("helm --kube-context kubecontext install skaffold-helm-remote stable/chartmuseum --repo https://charts.helm.sh/stable --kubeconfig kubeconfig", fmt.Errorf("building helm dependencies")),
helm: testDeployRemoteChart,
builds: testBuilds,
shouldErr: true,
},
{
Expand Down
87 changes: 87 additions & 0 deletions pkg/skaffold/event/v2/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2021 The Skaffold 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 v2

import (
"fmt"
"strconv"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
proto "github.com/GoogleContainerTools/skaffold/proto/v2"
)

const (
Cache = "Cache"
Build = "Build"
)

var artifactIDs = map[string]int{}

func AssignArtifactIDs(artifacts []*latestV1.Artifact) {
for i, a := range artifacts {
artifactIDs[a.ImageName] = i
}
}

func CacheCheckInProgress(artifact string) {
buildSubtaskEvent(artifact, Cache, Started, nil)
}

func CacheCheckMiss(artifact string) {
buildSubtaskEvent(artifact, Cache, Failed, nil)
}

func CacheCheckHit(artifact string) {
buildSubtaskEvent(artifact, Cache, Succeeded, nil)
}

func BuildInProgress(artifact string) {
buildSubtaskEvent(artifact, Build, Started, nil)
}

func BuildFailed(artifact string, err error) {
buildSubtaskEvent(artifact, Build, Failed, err)
}

func BuildSucceeded(artifact string) {
buildSubtaskEvent(artifact, Build, Succeeded, nil)
}

func buildSubtaskEvent(artifact, step, status string, err error) {
var aErr *proto.ActionableErr
if err != nil {
aErr = sErrors.ActionableErrV2(handler.cfg, constants.Build, err)
}
handler.handleBuildSubtaskEvent(&proto.BuildSubtaskEvent{
Id: strconv.Itoa(artifactIDs[artifact]),
TaskId: fmt.Sprintf("%s-%d", constants.Build, handler.iteration),
Artifact: artifact,
Step: step,
Status: status,
ActionableErr: aErr,
})
}

func (ev *eventHandler) handleBuildSubtaskEvent(e *proto.BuildSubtaskEvent) {
ev.handle(&proto.Event{
EventType: &proto.Event_BuildSubtaskEvent{
BuildSubtaskEvent: e,
},
})
}
45 changes: 5 additions & 40 deletions pkg/skaffold/event/v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"
"sync"

//nolint:golint,staticcheck
Expand Down Expand Up @@ -324,34 +323,6 @@ func TaskSucceeded(task constants.Phase) {
})
}

func BuildInProgress(id int, artifact string) {
handler.handleBuildSubtaskEvent(&proto.BuildSubtaskEvent{
Id: strconv.Itoa(id),
TaskId: fmt.Sprintf("%s-%d", constants.Build, handler.iteration),
Artifact: artifact,
Status: InProgress,
})
}

func BuildFailed(id int, artifact string, err error) {
handler.handleBuildSubtaskEvent(&proto.BuildSubtaskEvent{
Id: strconv.Itoa(id),
TaskId: fmt.Sprintf("%s-%d", constants.Build, handler.iteration),
Artifact: artifact,
Status: Failed,
ActionableErr: sErrors.ActionableErrV2(handler.cfg, constants.Build, err),
})
}

func BuildSucceeded(id int, artifact string) {
handler.handleBuildSubtaskEvent(&proto.BuildSubtaskEvent{
Id: strconv.Itoa(id),
TaskId: fmt.Sprintf("%s-%d", constants.Build, handler.iteration),
Artifact: artifact,
Status: Succeeded,
})
}

func (ev *eventHandler) setState(state proto.State) {
ev.stateLock.Lock()
ev.state = state
Expand All @@ -378,24 +349,18 @@ func (ev *eventHandler) handleTaskEvent(e *proto.TaskEvent) {
})
}

func (ev *eventHandler) handleBuildSubtaskEvent(e *proto.BuildSubtaskEvent) {
ev.handle(&proto.Event{
EventType: &proto.Event_BuildSubtaskEvent{
BuildSubtaskEvent: e,
},
})
}

func (ev *eventHandler) handleExec(event *proto.Event) {
switch e := event.GetEventType().(type) {
case *proto.Event_ApplicationLogEvent:
ev.logApplicationLog(event)
return
case *proto.Event_BuildSubtaskEvent:
be := e.BuildSubtaskEvent
ev.stateLock.Lock()
ev.state.BuildState.Artifacts[be.Artifact] = be.Status
ev.stateLock.Unlock()
if be.Step == Build {
ev.stateLock.Lock()
ev.state.BuildState.Artifacts[be.Artifact] = be.Status
ev.stateLock.Unlock()
}
case *proto.Event_TestEvent:
te := e.TestEvent
ev.stateLock.Lock()
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (r *Builder) GetBuilds() []graph.Artifact {
// Build builds a list of artifacts.
func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) {
eventV2.TaskInProgress(constants.Build)
eventV2.AssignArtifactIDs(artifacts)

// Use tags directly from the Kubernetes manifests.
if r.runCtx.DigestSource() == NoneDigestSource {
Expand Down
Loading

0 comments on commit 46a7610

Please sign in to comment.