Skip to content

Commit

Permalink
Update Stage API
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Mar 4, 2024
1 parent 9821a9a commit a51ed6c
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 133 deletions.
30 changes: 30 additions & 0 deletions pkg/apis/internalversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package internalversion

import (
"k8s.io/apimachinery/pkg/conversion"

configv1alpha1 "sigs.k8s.io/kwok/pkg/apis/config/v1alpha1"
"sigs.k8s.io/kwok/pkg/apis/v1alpha1"
"sigs.k8s.io/kwok/pkg/utils/path"
Expand Down Expand Up @@ -388,3 +390,31 @@ func ConvertToInternalMetric(in *v1alpha1.Metric) (*Metric, error) {
}
return &out, nil
}

// Convert_v1alpha1_StageNext_To_internalversion_StageNext converts a v1alpha1.StageNext to an internal version.
func Convert_v1alpha1_StageNext_To_internalversion_StageNext(in *v1alpha1.StageNext, out *StageNext, s conversion.Scope) error {
err := autoConvert_v1alpha1_StageNext_To_internalversion_StageNext(in, out, s)
if err != nil {
return err
}

if in.StatusTemplate != "" {
subresource := "status"
if in.StatusSubresource != nil {
subresource = *in.StatusSubresource
}
oldPatch := StagePatch{
Subresource: subresource,
Root: "status",
Template: in.StatusTemplate,
Impersonation: (*ImpersonationConfig)(in.StatusPatchAs),
}
out.Patches = append([]StagePatch{oldPatch}, out.Patches...)
}
return nil
}

// Convert_internalversion_StagePatch_To_v1alpha1_StagePatch converts an internal version StagePatch to a v1alpha1.StagePatch.
func Convert_internalversion_StagePatch_To_v1alpha1_StagePatch(in *StagePatch, out *v1alpha1.StagePatch, s conversion.Scope) error {
return autoConvert_internalversion_StagePatch_To_v1alpha1_StagePatch(in, out, s)
}
22 changes: 14 additions & 8 deletions pkg/apis/internalversion/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ type StageNext struct {
Finalizers *StageFinalizers
// Delete means that the resource will be deleted if true.
Delete bool
// StatusTemplate indicates the template for modifying the status of the resource in the next.
StatusTemplate string
// StatusSubresource indicates the name of the subresource that will be patched.
StatusSubresource string
// StatusPatchAs indicates the impersonating configuration for client when patching status.
// In most cases this will be empty, in which case the default client service account will be used.
// When this is not empty, a corresponding rbac change is required to grant `impersonate` privilege.
StatusPatchAs *ImpersonationConfig
// Patches means that the resource will be patched.
Patches []StagePatch
}

// StagePatch describes the patch for the resource.
type StagePatch struct {
// Subresource indicates the name of the subresource that will be patched
Subresource string
// Root indicates the root of the patch
Root string
// Template indicates the template for modifying the resource in the next.
Template string
// Impersonation indicates the impersonating configuration for client when patching.
Impersonation *ImpersonationConfig
}

// ImpersonationConfig describes the configuration for impersonating clients
Expand Down
67 changes: 54 additions & 13 deletions pkg/apis/internalversion/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions pkg/apis/internalversion/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/apis/v1alpha1/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,38 @@ type StageNext struct {
Finalizers *StageFinalizers `json:"finalizers,omitempty"`
// Delete means that the resource will be deleted if true.
Delete bool `json:"delete,omitempty"`
// Patches means that the resource will be patched.
Patches []StagePatch `json:"patches,omitempty"`

// StatusTemplate indicates the template for modifying the status of the resource in the next.
// Deprecated: Use Patches instead.
StatusTemplate string `json:"statusTemplate,omitempty"`
// StatusSubresource indicates the name of the subresource that will be patched. The support for
// this field is not available in Pod and Node resources.
// +default="status"
// +kubebuilder:default=status
// Deprecated: Use Patches instead.
StatusSubresource *string `json:"statusSubresource,omitempty"`
// StatusPatchAs indicates the impersonating configuration for client when patching status.
// In most cases this will be empty, in which case the default client service account will be used.
// When this is not empty, a corresponding rbac change is required to grant `impersonate` privilege.
// The support for this field is not available in Pod and Node resources.
// Deprecated: Use Patches instead.
StatusPatchAs *ImpersonationConfig `json:"statusPatchAs,omitempty"`
}

// StagePatch describes the patch for the resource.
type StagePatch struct {
// Subresource indicates the name of the subresource that will be patched
Subresource string `json:"subresource,omitempty"`
// Root indicates the root of the patch
Root string `json:"root,omitempty"`
// Template indicates the template for modifying the resource in the next.
Template string `json:"template,omitempty"`
// Impersonation indicates the impersonating configuration for client when patching.
Impersonation *ImpersonationConfig `json:"impersonation,omitempty"`
}

// ImpersonationConfig describes the configuration for impersonating clients
type ImpersonationConfig struct {
// Username the target username for the client to impersonate
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a51ed6c

Please sign in to comment.