Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pulumi/pulumi-kubernetes into bla…
Browse files Browse the repository at this point in the history
…mpe/2985
  • Loading branch information
blampe committed May 10, 2024
2 parents c6dd605 + 785d414 commit 0a4e29d
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 153 deletions.
5 changes: 2 additions & 3 deletions provider/cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"text/template"
"unicode"

"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/gen"
providerVersion "github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/version"
"github.com/pulumi/pulumi/pkg/v3/codegen"
Expand Down Expand Up @@ -520,7 +519,7 @@ func makeJSONString(v any) ([]byte, error) {
func mustWritePulumiSchema(pkgSpec schema.PackageSpec, version string) {
schemaJSON, err := makeJSONString(pkgSpec)
if err != nil {
panic(errors.Wrap(err, "marshaling Pulumi schema"))
panic(fmt.Errorf("marshaling Pulumi schema: %w", err))
}

mustWriteFile(BaseDir, filepath.Join("provider", "cmd", "pulumi-resource-kubernetes", "schema.json"), schemaJSON)
Expand All @@ -529,7 +528,7 @@ func mustWritePulumiSchema(pkgSpec schema.PackageSpec, version string) {
versionedPkgSpec.Version = version
versionedSchemaJSON, err := makeJSONString(versionedPkgSpec)
if err != nil {
panic(errors.Wrap(err, "marshaling Pulumi schema"))
panic(fmt.Errorf("marshaling Pulumi schema: %w", err))
}
mustWriteFile(BaseDir, filepath.Join("sdk", "schema", "schema.json"), versionedSchemaJSON)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.0
github.com/pkg/errors v0.9.1
github.com/pulumi/cloud-ready-checks v1.1.0
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.0.0
github.com/pulumi/pulumi-kubernetes/tests/v4 v4.0.0-20240302002028-652829a1ed71
Expand Down Expand Up @@ -293,6 +292,7 @@ require (
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.6.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
21 changes: 12 additions & 9 deletions provider/pkg/await/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"
"time"

"github.com/pkg/errors"
checkerlog "github.com/pulumi/cloud-ready-checks/pkg/checker/logging"
checkpod "github.com/pulumi/cloud-ready-checks/pkg/kubernetes/pod"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/await/informers"
Expand Down Expand Up @@ -915,29 +914,33 @@ func (dia *deploymentInitAwaiter) makeClients() (
deploymentClient, err = clients.ResourceClient(
kinds.Deployment, dia.config.currentOutputs.GetNamespace(), dia.config.clientSet)
if err != nil {
err = errors.Wrapf(err, "Could not make client to watch Deployment %q",
dia.config.currentOutputs.GetName())
err = fmt.Errorf("Could not make client to watch Deployment %q: %w",
dia.config.currentOutputs.GetName(), err)

return nil, nil, nil, nil, err
}
replicaSetClient, err = clients.ResourceClient(
kinds.ReplicaSet, dia.config.currentOutputs.GetNamespace(), dia.config.clientSet)
if err != nil {
err = errors.Wrapf(err, "Could not make client to watch ReplicaSets associated with Deployment %q",
dia.config.currentOutputs.GetName())
err = fmt.Errorf("Could not make client to watch ReplicaSets associated with Deployment %q: %w",
dia.config.currentOutputs.GetName(), err)

return nil, nil, nil, nil, err
}
podClient, err = clients.ResourceClient(
kinds.Pod, dia.config.currentOutputs.GetNamespace(), dia.config.clientSet)
if err != nil {
err = errors.Wrapf(err, "Could not make client to watch Pods associated with Deployment %q",
dia.config.currentOutputs.GetName())
err = fmt.Errorf("Could not make client to watch Pods associated with Deployment %q: %w",
dia.config.currentOutputs.GetName(), err)

return nil, nil, nil, nil, err
}
pvcClient, err = clients.ResourceClient(
kinds.PersistentVolumeClaim, dia.config.currentOutputs.GetNamespace(), dia.config.clientSet)
if err != nil {
err = errors.Wrapf(err, "Could not make client to watch PVCs associated with Deployment %q",
dia.config.currentOutputs.GetName())
err = fmt.Errorf("Could not make client to watch PVCs associated with Deployment %q: %w",
dia.config.currentOutputs.GetName(), err)

return nil, nil, nil, nil, err
}

Expand Down
19 changes: 9 additions & 10 deletions provider/pkg/await/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"reflect"
"time"

"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/await/informers"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/kinds"
Expand Down Expand Up @@ -510,23 +509,23 @@ func (iia *ingressInitAwaiter) makeClients() (
ingressClient, err = clients.ResourceClient(
kinds.Ingress, iia.config.currentOutputs.GetNamespace(), iia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch Ingress %q",
iia.config.currentOutputs.GetName())
return nil, nil, nil, fmt.Errorf("Could not make client to watch Ingress %q: %w",
iia.config.currentOutputs.GetName(), err)

}
endpointsClient, err = clients.ResourceClient(
kinds.Endpoints, iia.config.currentOutputs.GetNamespace(), iia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch Endpoints associated with Ingress %q",
iia.config.currentOutputs.GetName())
return nil, nil, nil, fmt.Errorf("Could not make client to watch Endpoints associated with Ingress %q: %w",
iia.config.currentOutputs.GetName(), err)

}
servicesClient, err = clients.ResourceClient(
kinds.Service, iia.config.currentOutputs.GetNamespace(), iia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch Services associated with Ingress %q",
iia.config.currentOutputs.GetName())
return nil, nil, nil, fmt.Errorf("Could not make client to watch Services associated with Ingress %q: %w",
iia.config.currentOutputs.GetName(), err)

}

return
Expand Down
6 changes: 2 additions & 4 deletions provider/pkg/await/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package await

import (
"fmt"
"strings"
"time"

"github.com/pkg/errors"
"github.com/pulumi/cloud-ready-checks/pkg/checker"
checkerlog "github.com/pulumi/cloud-ready-checks/pkg/checker/logging"
"github.com/pulumi/cloud-ready-checks/pkg/kubernetes/job"
Expand Down Expand Up @@ -161,9 +161,7 @@ func (jia *jobInitAwaiter) Read() error {

jobClient, err := clients.ResourceClient(kinds.Job, jia.config.currentOutputs.GetNamespace(), jia.config.clientSet)
if err != nil {
return errors.Wrapf(err,
"Could not make client to get Job %q",
jia.config.currentOutputs.GetName())
return fmt.Errorf("Could not make client to get Job %q: %w", jia.config.currentOutputs.GetName(), err)
}
// Get live version of Job.
job, err := jobClient.Get(jia.config.ctx, jia.config.currentOutputs.GetName(), metav1.GetOptions{})
Expand Down
6 changes: 2 additions & 4 deletions provider/pkg/await/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package await

import (
"fmt"
"time"

"github.com/pkg/errors"
"github.com/pulumi/cloud-ready-checks/pkg/checker"
"github.com/pulumi/cloud-ready-checks/pkg/checker/logging"
"github.com/pulumi/cloud-ready-checks/pkg/kubernetes/pod"
Expand Down Expand Up @@ -188,9 +188,7 @@ func (pia *podInitAwaiter) Read() error {
podClient, err := clients.ResourceClient(
kinds.Pod, pia.config.currentOutputs.GetNamespace(), pia.config.clientSet)
if err != nil {
return errors.Wrapf(err,
"Could not make client to get Pod %q",
pia.config.currentOutputs.GetName())
return fmt.Errorf("Could not make client to get Pod %q: %w", pia.config.currentOutputs.GetName(), err)
}
// Get live version of Pod.
pod, err := podClient.Get(pia.config.ctx, pia.config.currentOutputs.GetName(), metav1.GetOptions{})
Expand Down
13 changes: 6 additions & 7 deletions provider/pkg/await/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"
"time"

"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/await/informers"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/cluster"
Expand Down Expand Up @@ -421,16 +420,16 @@ func (sia *serviceInitAwaiter) makeClients() (
serviceClient, err = clients.ResourceClient(
kinds.Service, sia.config.currentOutputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, nil, errors.Wrapf(err,
"Could not make client to read Service %q",
sia.config.currentOutputs.GetName())
return nil, nil, fmt.Errorf("Could not make client to read Service %q: %w",
sia.config.currentOutputs.GetName(), err)

}
endpointClient, err = clients.ResourceClient(
kinds.Endpoints, sia.config.currentOutputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, nil, errors.Wrapf(err,
"Could not make client to read Endpoints associated with Service %q",
sia.config.currentOutputs.GetName())
return nil, nil, fmt.Errorf("Could not make client to read Endpoints associated with Service %q: %w",
sia.config.currentOutputs.GetName(), err)

}

return serviceClient, endpointClient, nil
Expand Down
13 changes: 6 additions & 7 deletions provider/pkg/await/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"
"time"

"github.com/pkg/errors"
"github.com/pulumi/cloud-ready-checks/pkg/checker/logging"
checkpod "github.com/pulumi/cloud-ready-checks/pkg/kubernetes/pod"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/await/informers"
Expand Down Expand Up @@ -510,16 +509,16 @@ func (sia *statefulsetInitAwaiter) makeClients() (
statefulSetClient, err = clients.ResourceClient(
kinds.StatefulSet, sia.config.currentOutputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, nil, errors.Wrapf(err,
"Could not make client to watch StatefulSet %q",
sia.config.currentOutputs.GetName())
return nil, nil, fmt.Errorf("Could not make client to watch StatefulSet %q: %w",
sia.config.currentOutputs.GetName(), err)

}
podClient, err = clients.ResourceClient(
kinds.Pod, sia.config.currentOutputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, nil, errors.Wrapf(err,
"Could not make client to watch Pods associated with StatefulSet %q",
sia.config.currentOutputs.GetName())
return nil, nil, fmt.Errorf("Could not make client to watch Pods associated with StatefulSet %q: %w",
sia.config.currentOutputs.GetName(), err)

}

return statefulSetClient, podClient, nil
Expand Down
55 changes: 29 additions & 26 deletions provider/pkg/provider/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
pbempty "github.com/golang/protobuf/ptypes/empty"
"github.com/imdario/mergo"
"github.com/mitchellh/mapstructure"
pkgerrors "github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/helm"
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/host"
Expand Down Expand Up @@ -348,7 +347,7 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
KeepSecrets: true,
})
if err != nil {
return nil, pkgerrors.Wrapf(err, "check failed because malformed resource inputs: %+v", err)
return nil, fmt.Errorf("check failed because malformed resource inputs: %w", err)
}

if len(olds) > 0 {
Expand Down Expand Up @@ -392,7 +391,7 @@ func (r *helmReleaseProvider) Check(ctx context.Context, req *pulumirpc.CheckReq
KeepSecrets: true,
})
if err != nil {
return nil, pkgerrors.Wrapf(err, "check failed because malformed resource inputs: %+v", err)
return nil, fmt.Errorf("check failed because malformed resource inputs: %w", err)
}
// ensure we don't leak secrets into state, and preserve the computedness of inputs.
annotateComputed(news, newInputs)
Expand Down Expand Up @@ -721,7 +720,7 @@ func (r *helmReleaseProvider) Diff(ctx context.Context, req *pulumirpc.DiffReque
KeepSecrets: true,
})
if err != nil {
return nil, pkgerrors.Wrapf(err, "diff failed because malformed resource inputs")
return nil, fmt.Errorf("diff failed because malformed resource inputs: %w", err)
}

// Extract old inputs from the `__inputs` field of the old state.
Expand Down Expand Up @@ -755,30 +754,31 @@ func (r *helmReleaseProvider) Diff(ctx context.Context, req *pulumirpc.DiffReque
// Later, we'll use this patch to generate a diff response, with special handling for the computed values.
oldInputsJSON, err := json.Marshal(oldInputs.MapRepl(nil, mapReplExtractValues))
if err != nil {
return nil, pkgerrors.Wrapf(err, "internal error: json.Marshal(oldInputsJson)")
return nil, fmt.Errorf("internal error: json.Marshal(oldInputsJson): %w", err)
}
logger.V(9).Infof("oldInputsJSON: %s", string(oldInputsJSON))
newInputsJSON, err := json.Marshal(news.MapRepl(nil, mapReplExtractValues))
if err != nil {
return nil, pkgerrors.Wrapf(err, "internal error: json.Marshal(oldInputsJson)")
return nil, fmt.Errorf("internal error: json.Marshal(oldInputsJson): %w", err)
}
logger.V(9).Infof("newInputsJSON: %s", string(newInputsJSON))
oldStateJSON, err := json.Marshal(olds.MapRepl(nil, mapReplExtractValues))
if err != nil {
return nil, pkgerrors.Wrapf(err, "internal error: json.Marshal(oldStateJson)")
return nil, fmt.Errorf("internal error: json.Marshal(oldStateJson): %w", err)
}
logger.V(9).Infof("oldStateJSON: %s", string(oldStateJSON))
strategicPatchJSON, err := strategicpatch.CreateThreeWayMergePatch(oldInputsJSON, newInputsJSON, oldStateJSON, &noSchema{}, true)
if err != nil {
return nil, pkgerrors.Wrapf(err, "internal error: CreateThreeWayMergePatch")
return nil, fmt.Errorf("internal error: CreateThreeWayMergePatch: %w", err)
}
logger.V(9).Infof("strategicPatchJSON: %s", string(strategicPatchJSON))
patchObj := map[string]any{}
if err = json.Unmarshal(strategicPatchJSON, &patchObj); err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to check for changes in Helm release %s/%s because of an error serializing "+
"the JSON patch describing resource changes",
oldRelease.Namespace, oldRelease.Name)
return nil, fmt.Errorf(
"Failed to check for changes in Helm release %s/%s because of an error serializing "+
"the JSON patch describing resource changes: %w",
oldRelease.Namespace, oldRelease.Name, err)

}

// Pack up PB, ship response back.
Expand All @@ -804,10 +804,11 @@ func (r *helmReleaseProvider) Diff(ctx context.Context, req *pulumirpc.DiffReque
}
forceNewFields := []string{".name", ".namespace"}
if detailedDiff, err = convertPatchToDiff(patchObj, strip(olds), strip(news), strip(oldInputs), forceNewFields...); err != nil {
return nil, pkgerrors.Wrapf(
err, "Failed to check for changes in helm release %s/%s because of an error "+
"converting JSON patch describing resource changes to a diff",
oldRelease.Namespace, oldRelease.Name)
return nil, fmt.Errorf(
"Failed to check for changes in helm release %s/%s because of an error "+
"converting JSON patch describing resource changes to a diff: %w",
oldRelease.Namespace, oldRelease.Name, err)

}

for k, v := range detailedDiff {
Expand Down Expand Up @@ -865,7 +866,7 @@ func (r *helmReleaseProvider) Create(ctx context.Context, req *pulumirpc.CreateR
KeepSecrets: true,
})
if err != nil {
return nil, pkgerrors.Wrapf(err, "create failed because malformed resource inputs")
return nil, fmt.Errorf("create failed because malformed resource inputs: %w", err)
}

newRelease, err := decodeRelease(news, fmt.Sprintf("%s.news", label))
Expand Down Expand Up @@ -906,9 +907,10 @@ func (r *helmReleaseProvider) Create(ctx context.Context, req *pulumirpc.CreateR
if creationError != nil {
return nil, partialError(
id,
pkgerrors.Wrapf(
creationError, "Helm release %q was created, but failed to initialize completely. "+
"Use Helm CLI to investigate.", id),
fmt.Errorf(
"Helm release %q was created, but failed to initialize completely. "+
"Use Helm CLI to investigate: %w", id, creationError),

inputsAndComputed,
nil)
}
Expand Down Expand Up @@ -1035,7 +1037,7 @@ func (r *helmReleaseProvider) Update(ctx context.Context, req *pulumirpc.UpdateR
KeepSecrets: true,
})
if err != nil {
return nil, pkgerrors.Wrapf(err, "update failed because malformed resource inputs")
return nil, fmt.Errorf("update failed because malformed resource inputs: %w", err)
}

logger.V(9).Infof("%s executing", label)
Expand Down Expand Up @@ -1080,9 +1082,10 @@ func (r *helmReleaseProvider) Update(ctx context.Context, req *pulumirpc.UpdateR
if updateError != nil {
return nil, partialError(
fqName(newRelease.Namespace, newRelease.Name),
pkgerrors.Wrapf(
updateError, "Helm release %q failed to initialize completely. "+
"Use Helm CLI to investigate.", fqName(newRelease.Namespace, newRelease.Name)),
fmt.Errorf(
"Helm release %q failed to initialize completely. "+
"Use Helm CLI to investigate: %w", fqName(newRelease.Namespace, newRelease.Name), updateError),

inputsAndComputed,
nil)
}
Expand Down Expand Up @@ -1525,7 +1528,7 @@ func locateChart(cpo *action.ChartPathOptions, registryClient *registry.Client,

// If not found, do more validations. This is from the original LocateChart.
if filepath.IsAbs(name) || strings.HasPrefix(name, ".") {
return name, pkgerrors.Errorf("path %q not found", name)
return name, fmt.Errorf("path %q not found", name)
}
}

Expand Down Expand Up @@ -1604,7 +1607,7 @@ func locateChart(cpo *action.ChartPathOptions, registryClient *registry.Client,
atVersion = fmt.Sprintf(" at version %q", version)
}

return filename, pkgerrors.Errorf("failed to download %q%s", name, atVersion)
return filename, fmt.Errorf("failed to download %q%s", name, atVersion)
}

func checkChartDependencies(c *helmchart.Chart, path, keyring string, settings *cli.EnvSettings,
Expand Down
Loading

0 comments on commit 0a4e29d

Please sign in to comment.