Skip to content

Commit

Permalink
Merge pull request #984 from wzshiming/feat/stage-api
Browse files Browse the repository at this point in the history
Add patches to instead of statusTemplate in Stage
  • Loading branch information
wzshiming authored Apr 22, 2024
2 parents afdef76 + c547675 commit 9b555d3
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 183 deletions.
40 changes: 38 additions & 2 deletions kustomize/crd/bases/kwok.x-k8s.io_stages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,46 @@ spec:
type: object
type: array
type: object
patches:
description: Patches means that the resource will be patched.
items:
description: StagePatch describes the patch for the resource.
properties:
impersonation:
description: |-
Impersonation 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.
properties:
username:
description: Username the target username for the client
to impersonate
type: string
required:
- username
type: object
root:
description: Root indicates the root of the template calculated
by the patch.
type: string
subresource:
description: Subresource indicates the name of the subresource
that will be patched.
type: string
template:
description: Template indicates the template for modifying
the resource in the next.
type: string
type: object
type: array
statusPatchAs:
description: |-
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.
properties:
username:
description: Username the target username for the client to
Expand All @@ -154,10 +188,12 @@ spec:
description: |-
StatusSubresource indicates the name of the subresource that will be patched. The support for
this field is not available in Pod and Node resources.
Deprecated: Use Patches instead.
type: string
statusTemplate:
description: StatusTemplate indicates the template for modifying
the status of the resource in the next.
description: |-
StatusTemplate indicates the template for modifying the status of the resource in the next.
Deprecated: Use Patches instead.
type: string
type: object
resourceRef:
Expand Down
40 changes: 40 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,41 @@ 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 != "" {
template := in.StatusTemplate

subresource := "status"
if in.StatusSubresource != nil {
subresource = *in.StatusSubresource
}

var impersonation *ImpersonationConfig
if in.StatusPatchAs != nil {
impersonation = &ImpersonationConfig{
Username: in.StatusPatchAs.Username,
}
}
patch := StagePatch{
Subresource: subresource,
Root: "status",
Template: template,
Impersonation: impersonation,
}

out.Patches = append([]StagePatch{patch}, 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)
}
21 changes: 15 additions & 6 deletions pkg/apis/internalversion/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,23 @@ 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.
// 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 template calculated by 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 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
// The support for this field is not available in Pod and Node resources.
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.

24 changes: 24 additions & 0 deletions pkg/apis/v1alpha1/stage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,44 @@ 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.
//+k8s:conversion-gen=false
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.
//+k8s:conversion-gen=false
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.
//+k8s:conversion-gen=false
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 template calculated by 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 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.
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 9b555d3

Please sign in to comment.