kubekey/pkg/proxy/resources/task/storage.go
dependabot[bot] 7b04037c5a
build(deps): bump github.com/stretchr/testify from 1.10.0 to 1.11.1 (#2796)
* build(deps): bump k8s.io/api from 0.31.3 to 0.34.1 (#2782)

Bumps [k8s.io/api](https://github.com/kubernetes/api) from 0.31.3 to 0.34.1.
- [Commits](https://github.com/kubernetes/api/compare/v0.31.3...v0.34.1)

---
updated-dependencies:
- dependency-name: k8s.io/api
  dependency-version: 0.34.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump golang.org/x/net from 0.33.0 to 0.45.0 (#2795)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.33.0 to 0.45.0.
- [Commits](https://github.com/golang/net/compare/v0.33.0...v0.45.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.45.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump golang.org/x/net from 0.32.0 to 0.38.0 in /api (#2790)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.32.0 to 0.38.0.
- [Commits](https://github.com/golang/net/compare/v0.32.0...v0.38.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.38.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/cloudflare/circl from 1.3.7 to 1.6.1 (#2788)

Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.7 to 1.6.1.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.7...v1.6.1)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-version: 1.6.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump goreleaser/goreleaser-action from 4 to 6 (#2787)

Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 4 to 6.
- [Release notes](https://github.com/goreleaser/goreleaser-action/releases)
- [Commits](https://github.com/goreleaser/goreleaser-action/compare/v4...v6)

---
updated-dependencies:
- dependency-name: goreleaser/goreleaser-action
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump oras.land/oras-go/v2 from 2.5.0 to 2.6.0 (#2783)

Bumps [oras.land/oras-go/v2](https://github.com/oras-project/oras-go) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/oras-project/oras-go/releases)
- [Commits](https://github.com/oras-project/oras-go/compare/v2.5.0...v2.6.0)

---
updated-dependencies:
- dependency-name: oras.land/oras-go/v2
  dependency-version: 2.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/go-git/go-git/v5 from 5.11.0 to 5.13.0 (#2785)

Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.11.0 to 5.13.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.11.0...v5.13.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-version: 5.13.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump golangci/golangci-lint-action from 6 to 8 (#2786)

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 6 to 8.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v6...v8)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/go-git/go-git/v5 from 5.11.0 to 5.16.3 (#2794)

Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.11.0 to 5.16.3.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.11.0...v5.16.3)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-version: 5.16.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): bump github.com/stretchr/testify from 1.10.0 to 1.11.1

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.10.0 to 1.11.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.10.0...v1.11.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-version: 1.11.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): update Go version and dependencies

- Bump Go version from 1.23.3 to 1.24.0.
- Update dependencies in go.mod:
  - github.com/fsnotify/fsnotify from v1.7.0 to v1.9.0
  - github.com/spf13/cobra from v1.8.1 to v1.9.1
  - k8s.io/apiserver, k8s.io/client-go, and k8s.io/component-base from v0.31.3 to v0.34.1
  - sigs.k8s.io/controller-runtime from v0.19.3 to v0.22.4
  - Various other indirect dependencies updated to their latest versions.

This update ensures compatibility with the latest features and fixes in the Go ecosystem.

Signed-off-by: redscholar <blacktiledhouse@gmail.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: redscholar <blacktiledhouse@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: redscholar <blacktiledhouse@gmail.com>
Co-authored-by: liujian <joyceliu@yunify.com>
2025-12-26 11:57:36 +00:00

111 lines
3.8 KiB
Go

/*
Copyright 2024 The KubeSphere 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 task
import (
"context"
"github.com/cockroachdb/errors"
kkcorev1alpha1 "github.com/kubesphere/kubekey/api/core/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
apigeneric "k8s.io/apiserver/pkg/registry/generic"
apiregistry "k8s.io/apiserver/pkg/registry/generic/registry"
apirest "k8s.io/apiserver/pkg/registry/rest"
apistorage "k8s.io/apiserver/pkg/storage"
)
// TaskStorage storage for Task
type TaskStorage struct {
Task *REST
TaskStatus *StatusREST
}
// REST resource for Task
type REST struct {
*apiregistry.Store
}
// StatusREST status subresource for Task
type StatusREST struct {
store *apiregistry.Store
}
// NamespaceScoped is true for Task
func (r *StatusREST) NamespaceScoped() bool {
return true
}
// New creates a new Node object.
func (r *StatusREST) New() runtime.Object {
return &kkcorev1alpha1.Task{}
}
// Destroy cleans up resources on shutdown.
func (r *StatusREST) Destroy() {
// Given that underlying store is shared with REST,
// we don't destroy it here explicitly.
}
// Get retrieves the object from the storage. It is required to support Patch.
func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
return r.store.Get(ctx, name, options)
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx context.Context, name string, objInfo apirest.UpdatedObjectInfo, createValidation apirest.ValidateObjectFunc, updateValidation apirest.ValidateObjectUpdateFunc, _ bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
// We are explicitly setting forceAllowCreate to false in the call to the underlying storage because
// subresources should never allow create on update.
return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options)
}
// ConvertToTable print table view
func (r *StatusREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
return r.store.ConvertToTable(ctx, object, tableOptions)
}
// NewStorage for Task storage
func NewStorage(optsGetter apigeneric.RESTOptionsGetter) (TaskStorage, error) {
store := &apiregistry.Store{
NewFunc: func() runtime.Object { return &kkcorev1alpha1.Task{} },
NewListFunc: func() runtime.Object { return &kkcorev1alpha1.TaskList{} },
PredicateFunc: MatchTask,
DefaultQualifiedResource: kkcorev1alpha1.SchemeGroupVersion.WithResource("tasks").GroupResource(),
SingularQualifiedResource: kkcorev1alpha1.SchemeGroupVersion.WithResource("task").GroupResource(),
CreateStrategy: Strategy,
UpdateStrategy: Strategy,
DeleteStrategy: Strategy,
ReturnDeletedObject: true,
TableConvertor: apirest.NewDefaultTableConvertor(kkcorev1alpha1.SchemeGroupVersion.WithResource("tasks").GroupResource()),
}
options := &apigeneric.StoreOptions{
RESTOptions: optsGetter,
AttrFunc: GetAttrs,
TriggerFunc: map[string]apistorage.IndexerFunc{"metadata.name": NameTriggerFunc},
}
if err := store.CompleteWithOptions(options); err != nil {
return TaskStorage{}, errors.Wrap(err, "failed to complete store")
}
return TaskStorage{
Task: &REST{store},
TaskStatus: &StatusREST{store},
}, nil
}