Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version v1beta1 and conversion webhook #171

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: kruise.io
layout:
- go.kubebuilder.io/v3
Expand All @@ -21,4 +25,64 @@ resources:
kind: BatchRelease
path: github.com/openkruise/rollouts/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: RolloutHistory
path: github.com/openkruise/rollouts/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: TrafficRouting
path: github.com/openkruise/rollouts/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: Rollout
path: github.com/openkruise/rollouts/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: TrafficRouting
path: github.com/openkruise/rollouts/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: BatchRelease
path: github.com/openkruise/rollouts/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: kruise.io
group: rollouts
kind: RolloutHistory
path: github.com/openkruise/rollouts/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
version: "3"
26 changes: 26 additions & 0 deletions api/addtoscheme_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2019 The Kruise 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 apis

import (
"github.com/openkruise/rollouts/api/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
}
24 changes: 24 additions & 0 deletions api/addtoscheme_v1beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2019 The Kruise 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 apis

import "github.com/openkruise/rollouts/api/v1beta1"

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme)
}
29 changes: 29 additions & 0 deletions api/apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2020 The Kruise 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 apis

import (
"k8s.io/apimachinery/pkg/runtime"
)

// AddToSchemes may be used to add all resources defined in the project to a Scheme
var AddToSchemes runtime.SchemeBuilder

// AddToScheme adds all Resources to the Scheme
func AddToScheme(s *runtime.Scheme) error {
return AddToSchemes.AddToScheme(s)
}
132 changes: 132 additions & 0 deletions api/v1alpha1/batchrelease_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package v1alpha1

import (
"fmt"

"github.com/openkruise/rollouts/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *BatchRelease) ConvertTo(dstRaw conversion.Hub) error {
switch t := dstRaw.(type) {
case *v1beta1.BatchRelease:
dst := dstRaw.(*v1beta1.BatchRelease)
dst.ObjectMeta = src.ObjectMeta

// batchrelease spec conversion
dst.Spec.TargetRef.WorkloadRef = &v1beta1.WorkloadRef{
APIVersion: src.Spec.TargetRef.WorkloadRef.APIVersion,
Kind: src.Spec.TargetRef.WorkloadRef.Kind,
Name: src.Spec.TargetRef.WorkloadRef.Name,
}
batches := make([]v1beta1.ReleaseBatch, len(src.Spec.ReleasePlan.Batches))
for i, v := range src.Spec.ReleasePlan.Batches {
batches[i].CanaryReplicas = v.CanaryReplicas
}
dst.Spec.ReleasePlan = v1beta1.ReleasePlan{
Batches: batches,
BatchPartition: src.Spec.ReleasePlan.BatchPartition,
RolloutID: src.Spec.ReleasePlan.RolloutID,
FailureThreshold: src.Spec.ReleasePlan.FailureThreshold,
FinalizingPolicy: v1beta1.FinalizingPolicyType(src.Spec.ReleasePlan.FinalizingPolicy),
PatchPodTemplateMetadata: (*v1beta1.PatchPodTemplateMetadata)(src.Spec.ReleasePlan.PatchPodTemplateMetadata),
}

// batchrelease status conversion
conditions := make([]v1beta1.RolloutCondition, len(src.Status.Conditions))
for i, v := range src.Status.Conditions {
conditions[i] = v1beta1.RolloutCondition{
Type: v1beta1.RolloutConditionType(v.Type),
Status: v.Status,
LastUpdateTime: v.LastUpdateTime,
LastTransitionTime: v.LastTransitionTime,
Reason: v.Reason,
Message: v.Message,
}
}
dst.Status = v1beta1.BatchReleaseStatus{
Conditions: conditions,
CanaryStatus: v1beta1.BatchReleaseCanaryStatus{
CurrentBatchState: v1beta1.BatchReleaseBatchStateType(src.Status.CanaryStatus.CurrentBatchState),
CurrentBatch: src.Status.CanaryStatus.CurrentBatch,
BatchReadyTime: src.Status.CanaryStatus.BatchReadyTime,
UpdatedReplicas: src.Status.CanaryStatus.UpdatedReplicas,
UpdatedReadyReplicas: src.Status.CanaryStatus.UpdatedReadyReplicas,
NoNeedUpdateReplicas: src.Status.CanaryStatus.NoNeedUpdateReplicas,
},
StableRevision: src.Status.StableRevision,
UpdateRevision: src.Status.UpdateRevision,
ObservedGeneration: src.Status.ObservedGeneration,
ObservedRolloutID: src.Status.ObservedRolloutID,
ObservedWorkloadReplicas: src.Status.ObservedWorkloadReplicas,
CollisionCount: src.Status.CollisionCount,
ObservedReleasePlanHash: src.Status.ObservedReleasePlanHash,
Phase: v1beta1.RolloutPhase(src.Status.Phase),
}
default:
return fmt.Errorf("unsupported type %v", t)
}
return nil
}

func (dst *BatchRelease) ConvertFrom(srcRaw conversion.Hub) error {
switch t := srcRaw.(type) {
case *v1beta1.BatchRelease:
src := srcRaw.(*v1beta1.BatchRelease)
dst.ObjectMeta = src.ObjectMeta

// batchrelease spec conversion
dst.Spec.TargetRef.WorkloadRef = &WorkloadRef{
APIVersion: src.Spec.TargetRef.WorkloadRef.APIVersion,
Kind: src.Spec.TargetRef.WorkloadRef.Kind,
Name: src.Spec.TargetRef.WorkloadRef.Name,
}
batches := make([]ReleaseBatch, len(src.Spec.ReleasePlan.Batches))
for i, v := range src.Spec.ReleasePlan.Batches {
batches[i].CanaryReplicas = v.CanaryReplicas
}
dst.Spec.ReleasePlan = ReleasePlan{
Batches: batches,
BatchPartition: src.Spec.ReleasePlan.BatchPartition,
RolloutID: src.Spec.ReleasePlan.RolloutID,
FailureThreshold: src.Spec.ReleasePlan.FailureThreshold,
FinalizingPolicy: FinalizingPolicyType(src.Spec.ReleasePlan.FinalizingPolicy),
PatchPodTemplateMetadata: (*PatchPodTemplateMetadata)(src.Spec.ReleasePlan.PatchPodTemplateMetadata),
}

// batchrelease status conversion
conditions := make([]RolloutCondition, len(src.Status.Conditions))
for i, v := range src.Status.Conditions {
conditions[i] = RolloutCondition{
Type: RolloutConditionType(v.Type),
Status: v.Status,
LastUpdateTime: v.LastUpdateTime,
LastTransitionTime: v.LastTransitionTime,
Reason: v.Reason,
Message: v.Message,
}
}
dst.Status = BatchReleaseStatus{
Conditions: conditions,
CanaryStatus: BatchReleaseCanaryStatus{
CurrentBatchState: BatchReleaseBatchStateType(src.Status.CanaryStatus.CurrentBatchState),
CurrentBatch: src.Status.CanaryStatus.CurrentBatch,
BatchReadyTime: src.Status.CanaryStatus.BatchReadyTime,
UpdatedReplicas: src.Status.CanaryStatus.UpdatedReplicas,
UpdatedReadyReplicas: src.Status.CanaryStatus.UpdatedReadyReplicas,
NoNeedUpdateReplicas: src.Status.CanaryStatus.NoNeedUpdateReplicas,
},
StableRevision: src.Status.StableRevision,
UpdateRevision: src.Status.UpdateRevision,
ObservedGeneration: src.Status.ObservedGeneration,
ObservedRolloutID: src.Status.ObservedRolloutID,
ObservedWorkloadReplicas: src.Status.ObservedWorkloadReplicas,
CollisionCount: src.Status.CollisionCount,
ObservedReleasePlanHash: src.Status.ObservedReleasePlanHash,
Phase: RolloutPhase(src.Status.Phase),
}
default:
return fmt.Errorf("unsupported type %v", t)
}
return nil
}
Loading
Loading