Skip to content

Commit

Permalink
fix: error if a resource group/kind is not available in the cluster a…
Browse files Browse the repository at this point in the history
…nymore
  • Loading branch information
JGiola committed Oct 8, 2024
1 parent 71a6981 commit 8264a2b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- hanging if no resources has been applied successfully in a step
- error if a group/kind of a resource saved in the old inventory format is not availbale anymore in the cluster
now we skip the resource because we cannot retrieve it

## [v2.0.0-beta.2] - 2024-10-04

### Changed
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/external-secrets/external-secrets v0.10.0
github.com/go-logr/logr v1.4.2
github.com/go-logr/stdr v1.2.2
github.com/mia-platform/jpl v0.5.0
github.com/mia-platform/jpl v0.5.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mia-platform/jpl v0.5.0 h1:DF6hMMZvMZxabHfpZ1xvfIDOirufsRWt64vynoGwEaA=
github.com/mia-platform/jpl v0.5.0/go.mod h1:fo3TIOpsOhO4sQLgQxhCy4CBOo0BvLRCzgk2fAggvs4=
github.com/mia-platform/jpl v0.5.1 h1:3KpKtOk3Nf8p9DofpO6uCONMsJpyo9v10Tp/cD7Qgeo=
github.com/mia-platform/jpl v0.5.1/go.mod h1:fo3TIOpsOhO4sQLgQxhCy4CBOo0BvLRCzgk2fAggvs4=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/deploy/convert_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (s *Inventory) oldInventoryObjects(ctx context.Context) (sets.Set[resource.

mapping, err := s.mapper.RESTMapping(gvk.GroupKind())
if err != nil {
if meta.IsNoMatchError(err) {
continue
}
return nil, err
}

Expand Down
51 changes: 51 additions & 0 deletions pkg/cmd/deploy/convert_inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,57 @@ func TestLoadInventory(t *testing.T) { //nolint: gocyclo
}),
expectedError: fmt.Sprintf("unexpected call: %q, method GET", secretPath),
},
"unavailable kind in compatibility mode": {
client: restfake.CreateHTTPClient(func(r *http.Request) (*http.Response, error) {
path := r.URL.Path
method := r.Method
switch {
case path == configMapPath && method == http.MethodGet:
return &http.Response{StatusCode: http.StatusNotFound, Header: jpltesting.DefaultHeaders()}, nil
case path == secretPath && method == http.MethodGet:
data, err := json.Marshal(map[string]*oldResourceList{
"Deployment": {
Kind: "Deployment",
Mapping: schema.GroupVersionResource{
Group: "apps",
Version: "v1",
Resource: "deployments",
},
Resources: []string{"example"},
},
"Namespace": {
Kind: "Namespace",
Mapping: schema.GroupVersionResource{
Group: "",
Version: "v1",
Resource: "namespaces",
},
Resources: []string{"example"},
},
"Foo": {
Kind: "Foo",
Mapping: schema.GroupVersionResource{
Group: "example.com",
Version: "v1alpha1",
Resource: "foos",
},
},
})
require.NoError(t, err)
sec := &corev1.Secret{Data: map[string][]byte{
oldInventoryKey: data,
}}
body := io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, sec))))
return &http.Response{StatusCode: http.StatusOK, Body: body, Header: jpltesting.DefaultHeaders()}, nil
}

return nil, fmt.Errorf("unexpected call: %q, method %s", path, method)
}),
expectedSet: sets.New(
deployResource,
namespaceResource,
),
},
}

for name, test := range tests {
Expand Down

0 comments on commit 8264a2b

Please sign in to comment.