Skip to content

Commit

Permalink
chore: rename api version from apps.v1 to apps.v1beta1 (apecloud#6938)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Apr 2, 2024
1 parent bc7b9f5 commit 728ee72
Show file tree
Hide file tree
Showing 137 changed files with 10,322 additions and 10,304 deletions.
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ resources:
domain: kubeblocks.io
group: apps
kind: ConfigConstraint
path: github.com/apecloud/kubeblocks/apis/apps/v1
path: github.com/apecloud/kubeblocks/apis/apps/v1beta1
version: v1
webhooks:
conversion: true
Expand Down
59 changes: 34 additions & 25 deletions apis/apps/v1alpha1/configconstraint_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,45 @@ package v1alpha1
import (
"errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/conversion"
logf "sigs.k8s.io/controller-runtime/pkg/log"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
"github.com/apecloud/kubeblocks/pkg/constant"
)

var logger = logf.Log.WithName("application-resource")

func (cc *ConfigConstraint) ConvertTo(dstRaw conversion.Hub) error {
logger.Info("Conversion Webhook: From v1alpha1 to v1")
ccv1, ok := dstRaw.(*appsv1.ConfigConstraint)
logger.Info("Conversion Webhook: from v1alpha1 to v1", "name", cc.Name)
ccv1, ok := dstRaw.(*appsv1beta1.ConfigConstraint)
if !ok {
return errors.New("invalid destination object")
}
return convertToImpl(cc, ccv1)
}

func (cc *ConfigConstraint) ConvertFrom(srcRaw conversion.Hub) error {
logger.Info("Conversion Webhook: From v1 to v1beta1")
ccv1, ok := srcRaw.(*appsv1.ConfigConstraint)
ccv1, ok := srcRaw.(*appsv1beta1.ConfigConstraint)
if !ok {
return errors.New("invalid source object")
}
logger.Info("Conversion Webhook: from v1 to v1alpha1", "name", ccv1.Name)
return convertFromImpl(ccv1, cc)
}

func convertToImpl(cc *ConfigConstraint, ccv1 *appsv1.ConfigConstraint) error {
convertObjectMeta(cc.ObjectMeta, ccv1)
func convertToImpl(cc *ConfigConstraint, ccv1 *appsv1beta1.ConfigConstraint) error {
ccv1.ObjectMeta = cc.ObjectMeta
if ccv1.Annotations == nil {
ccv1.Annotations = make(map[string]string)
}
ccv1.Annotations[constant.KubeblocksAPIConversionTypeAnnotationName] = constant.MigratedAPIVersion
ccv1.Annotations[constant.SourceAPIVersionAnnotationName] = GroupVersion.Version
convertToConstraintSpec(&cc.Spec, &ccv1.Spec)
return nil
}

func convertObjectMeta(src metav1.ObjectMeta, dst client.Object) {
dst.SetLabels(src.GetLabels())
dst.SetAnnotations(src.GetAnnotations())
}

func convertToConstraintSpec(cc *ConfigConstraintSpec, ccv1 *appsv1.ConfigConstraintSpec) {
func convertToConstraintSpec(cc *ConfigConstraintSpec, ccv1 *appsv1beta1.ConfigConstraintSpec) {
ccv1.DynamicActionCanBeMerged = cc.DynamicActionCanBeMerged
ccv1.DynamicParameterSelectedPolicy = cc.DynamicParameterSelectedPolicy
ccv1.ReloadToolsImage = cc.ToolsImageSpec
Expand All @@ -77,36 +76,46 @@ func convertToConstraintSpec(cc *ConfigConstraintSpec, ccv1 *appsv1.ConfigConstr
convertSchema(cc.ConfigurationSchema, ccv1)
}

func convertSchema(schema *CustomParametersValidation, ccv1 *appsv1.ConfigConstraintSpec) {
if schema != nil {
func convertSchema(schema *CustomParametersValidation, ccv1 *appsv1beta1.ConfigConstraintSpec) {
if schema == nil {
return
}

ccv1.ConfigSchema = &appsv1.ConfigSchema{
ccv1.ConfigSchema = &appsv1beta1.ConfigSchema{
CUE: schema.CUE,
SchemaInJSON: schema.Schema,
}
}

func convertDynamicReloadAction(options *ReloadOptions, ccv1 *appsv1.ConfigConstraintSpec) {
if options != nil {
func convertDynamicReloadAction(options *ReloadOptions, ccv1 *appsv1beta1.ConfigConstraintSpec) {
if options == nil {
return
}
ccv1.DynamicReloadAction = &appsv1.DynamicReloadAction{
ccv1.DynamicReloadAction = &appsv1beta1.DynamicReloadAction{
UnixSignalTrigger: options.UnixSignalTrigger,
ShellTrigger: options.ShellTrigger,
TPLScriptTrigger: options.TPLScriptTrigger,
AutoTrigger: options.AutoTrigger,
}
}

func convertFromImpl(ccv1 *appsv1.ConfigConstraint, cc *ConfigConstraint) error {
convertObjectMeta(ccv1.ObjectMeta, cc)
func convertFromImpl(ccv1 *appsv1beta1.ConfigConstraint, cc *ConfigConstraint) error {
cc.ObjectMeta = ccv1.ObjectMeta
if cc.Annotations == nil {
cc.Annotations = make(map[string]string)
}

vType, ok := ccv1.Annotations[constant.KubeblocksAPIConversionTypeAnnotationName]
if ok && vType == constant.MigratedAPIVersion && ccv1.Annotations[constant.SourceAPIVersionAnnotationName] == GroupVersion.Version {
cc.Annotations[constant.KubeblocksAPIConversionTypeAnnotationName] = constant.SourceAPIVersion
} else {
cc.Annotations[constant.KubeblocksAPIConversionTypeAnnotationName] = constant.ReviewAPIVersion
}

convertFromConstraintSpec(&ccv1.Spec, &cc.Spec)
return nil
}

func convertFromConstraintSpec(ccv1 *appsv1.ConfigConstraintSpec, cc *ConfigConstraintSpec) {
func convertFromConstraintSpec(ccv1 *appsv1beta1.ConfigConstraintSpec, cc *ConfigConstraintSpec) {
cc.DynamicActionCanBeMerged = ccv1.DynamicActionCanBeMerged
cc.DynamicParameterSelectedPolicy = ccv1.DynamicParameterSelectedPolicy
cc.ToolsImageSpec = ccv1.ReloadToolsImage
Expand Down
22 changes: 11 additions & 11 deletions apis/apps/v1alpha1/configconstraint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
)

// ConfigConstraintSpec defines the desired state of ConfigConstraint
Expand All @@ -43,13 +43,13 @@ type ConfigConstraintSpec struct {
// Specifies the policy for selecting the parameters of dynamic reload actions.
//
// +optional
DynamicParameterSelectedPolicy *v1.DynamicParameterSelectedPolicy `json:"dynamicParameterSelectedPolicy,omitempty"`
DynamicParameterSelectedPolicy *appsv1beta1.DynamicParameterSelectedPolicy `json:"dynamicParameterSelectedPolicy,omitempty"`

// Tools used by the dynamic reload actions.
// Usually it is referenced by the 'init container' for 'cp' it to a binary volume.
//
// +optional
ToolsImageSpec *v1.ReloadToolsImage `json:"toolsImageSpec,omitempty"`
ToolsImageSpec *appsv1beta1.ReloadToolsImage `json:"toolsImageSpec,omitempty"`

// A set of actions for regenerating local configs.
//
Expand All @@ -58,7 +58,7 @@ type ConfigConstraintSpec struct {
// - after a role switch, the local config will be regenerated with the help of DownwardActions
//
// +optional
DownwardAPIOptions []v1.DownwardAction `json:"downwardAPIOptions,omitempty"`
DownwardAPIOptions []appsv1beta1.DownwardAction `json:"downwardAPIOptions,omitempty"`

// A list of ScriptConfig used by the actions defined in dynamic reload and downward actions.
//
Expand All @@ -67,7 +67,7 @@ type ConfigConstraintSpec struct {
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=scriptConfigMapRef
ScriptConfigs []v1.ScriptConfig `json:"scriptConfigs,omitempty"`
ScriptConfigs []appsv1beta1.ScriptConfig `json:"scriptConfigs,omitempty"`

// Top level key used to get the cue rules to validate the config file.
// It must exist in 'ConfigSchema'
Expand Down Expand Up @@ -110,7 +110,7 @@ type ConfigConstraintSpec struct {
// 3. Trigger the corresponding action
//
// +kubebuilder:validation:Required
FormatterConfig *v1.FormatterConfig `json:"formatterConfig"`
FormatterConfig *appsv1beta1.FormatterConfig `json:"formatterConfig"`
}

// Represents the observed state of a ConfigConstraint.
Expand All @@ -121,7 +121,7 @@ type ConfigConstraintStatus struct {
// When set to CCAvailablePhase, the ConfigConstraint can be referenced by ClusterDefinition or ClusterVersion.
//
// +optional
Phase v1.ConfigConstraintPhase `json:"phase,omitempty"`
Phase appsv1beta1.ConfigConstraintPhase `json:"phase,omitempty"`

// Provides descriptions for abnormal states.
//
Expand Down Expand Up @@ -155,22 +155,22 @@ type ReloadOptions struct {
// Used to trigger a reload by sending a Unix signal to the process.
//
// +optional
UnixSignalTrigger *v1.UnixSignalTrigger `json:"unixSignalTrigger,omitempty"`
UnixSignalTrigger *appsv1beta1.UnixSignalTrigger `json:"unixSignalTrigger,omitempty"`

// Used to perform the reload command in shell script.
//
// +optional
ShellTrigger *v1.ShellTrigger `json:"shellTrigger,omitempty"`
ShellTrigger *appsv1beta1.ShellTrigger `json:"shellTrigger,omitempty"`

// Used to perform the reload command by Go template script.
//
// +optional
TPLScriptTrigger *v1.TPLScriptTrigger `json:"tplScriptTrigger"`
TPLScriptTrigger *appsv1beta1.TPLScriptTrigger `json:"tplScriptTrigger"`

// Used to automatically perform the reload command when conditions are met.
//
// +optional
AutoTrigger *v1.AutoTrigger `json:"autoTrigger,omitempty"`
AutoTrigger *appsv1beta1.AutoTrigger `json:"autoTrigger,omitempty"`
}

// +genclient
Expand Down
12 changes: 6 additions & 6 deletions apis/apps/v1alpha1/configconstraint_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (

"github.com/stretchr/testify/assert"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
)

func TestConfigConstraintStatus_IsConfigConstraintTerminalPhases(t *testing.T) {
type fields struct {
Phase appsv1.ConfigConstraintPhase
Phase appsv1beta1.ConfigConstraintPhase
Message string
ObservedGeneration int64
}
Expand All @@ -40,19 +40,19 @@ func TestConfigConstraintStatus_IsConfigConstraintTerminalPhases(t *testing.T) {
}{{
name: "available phase test",
fields: fields{
Phase: appsv1.CCAvailablePhase,
Phase: appsv1beta1.CCAvailablePhase,
},
want: true,
}, {
name: "available phase test",
fields: fields{
Phase: appsv1.CCUnavailablePhase,
Phase: appsv1beta1.CCUnavailablePhase,
},
want: false,
}, {
name: "available phase test",
fields: fields{
Phase: appsv1.CCDeletingPhase,
Phase: appsv1beta1.CCDeletingPhase,
},
want: false,
}}
Expand All @@ -63,7 +63,7 @@ func TestConfigConstraintStatus_IsConfigConstraintTerminalPhases(t *testing.T) {
Message: tt.fields.Message,
ObservedGeneration: tt.fields.ObservedGeneration,
}
assert.Equalf(t, tt.want, cs.Phase == appsv1.CCAvailablePhase, "ConfigConstraintTerminalPhases()")
assert.Equalf(t, tt.want, cs.Phase == appsv1beta1.CCAvailablePhase, "ConfigConstraintTerminalPhases()")
})
}
}
6 changes: 3 additions & 3 deletions apis/apps/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
"github.com/apecloud/kubeblocks/pkg/testutil"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)
Expand Down Expand Up @@ -104,7 +104,7 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = appsv1.AddToScheme(scheme)
err = appsv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1.AddToScheme(scheme)
Expand Down Expand Up @@ -146,7 +146,7 @@ var _ = BeforeSuite(func() {
&Cluster{},
&ClusterVersion{},
&OpsRequest{},
&appsv1.ConfigConstraint{},
&appsv1beta1.ConfigConstraint{},
},
},
},
Expand Down
20 changes: 10 additions & 10 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1
package v1beta1

func (r *ConfigConstraint) Hub() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1
package v1beta1

import (
corev1 "k8s.io/api/core/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1
package v1beta1

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1
package v1beta1

import (
"text/template/parse"
Expand Down
Loading

0 comments on commit 728ee72

Please sign in to comment.