mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 10:00:11 +00:00
Some checks failed
Post / images (amd64, addon-manager) (push) Failing after 46s
Post / images (amd64, placement) (push) Failing after 41s
Post / images (amd64, registration-operator) (push) Failing after 39s
Post / images (amd64, work) (push) Failing after 42s
Post / images (arm64, addon-manager) (push) Failing after 39s
Post / images (arm64, placement) (push) Failing after 39s
Post / images (arm64, registration) (push) Failing after 40s
Post / images (arm64, registration-operator) (push) Failing after 42s
Post / images (arm64, work) (push) Failing after 39s
Post / images (amd64, registration) (push) Failing after 7m46s
Post / image manifest (addon-manager) (push) Has been skipped
Post / image manifest (placement) (push) Has been skipped
Post / image manifest (registration) (push) Has been skipped
Post / image manifest (registration-operator) (push) Has been skipped
Post / image manifest (work) (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Post / coverage (push) Failing after 14m33s
Scorecard supply-chain security / Scorecard analysis (push) Failing after 1m25s
Close stale issues and PRs / stale (push) Successful in 46s
* Add addon conversion webhook for v1alpha1/v1beta1 API migration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Qing Hao <qhao@redhat.com> * Fix GroupVersion compatibility issues after API dependency update This commit fixes compilation and test errors introduced by updating the API dependency to use native conversion functions from PR #411. Changes include: 1. Fix GroupVersion type mismatches across the codebase: - Updated OwnerReference creation to use schema.GroupVersion - Fixed webhook scheme registration to use proper GroupVersion type - Applied fixes to addon, placement, migration, work, and registration controllers 2. Enhance addon conversion webhook: - Use native API conversion functions from addon/v1beta1/conversion.go - Fix InstallNamespace annotation key to match expected format - Add custom logic to populate deprecated ConfigReferent field in ConfigReferences - Properly preserve annotations during v1alpha1 <-> v1beta1 conversion 3. Remove duplicate conversion code: - Deleted pkg/addon/webhook/conversion/ directory (~500 lines) - Now using native conversion functions from the API repository 4. Patch vendored addon-framework: - Fixed GroupVersion errors in agentdeploy utils All unit tests pass successfully (97 packages, 0 failures). Signed-off-by: Qing Hao <qhao@redhat.com> --------- Signed-off-by: Qing Hao <qhao@redhat.com> Co-authored-by: Claude <noreply@anthropic.com>
439 lines
13 KiB
Go
439 lines
13 KiB
Go
// Copyright Contributors to the Open Cluster Management project
|
|
|
|
package v1beta1
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
|
|
addonv1beta1 "open-cluster-management.io/api/addon/v1beta1"
|
|
clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1"
|
|
|
|
internalv1alpha1 "open-cluster-management.io/ocm/pkg/addon/webhook/v1alpha1"
|
|
)
|
|
|
|
func TestClusterManagementAddOnConvertTo(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
src *ClusterManagementAddOn
|
|
expected *internalv1alpha1.ClusterManagementAddOn
|
|
}{
|
|
{
|
|
name: "complete conversion with all fields",
|
|
src: &ClusterManagementAddOn{
|
|
ClusterManagementAddOn: addonv1beta1.ClusterManagementAddOn{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-addon",
|
|
},
|
|
Spec: addonv1beta1.ClusterManagementAddOnSpec{
|
|
AddOnMeta: addonv1beta1.AddOnMeta{
|
|
DisplayName: "Test AddOn",
|
|
Description: "Test description",
|
|
},
|
|
DefaultConfigs: []addonv1beta1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
InstallStrategy: addonv1beta1.InstallStrategy{
|
|
Type: addonv1beta1.AddonInstallStrategyPlacements,
|
|
Placements: []addonv1beta1.PlacementStrategy{
|
|
{
|
|
PlacementRef: addonv1beta1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
Configs: []addonv1beta1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
RolloutStrategy: clusterv1alpha1.RolloutStrategy{
|
|
Type: clusterv1alpha1.All,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Status: addonv1beta1.ClusterManagementAddOnStatus{
|
|
DefaultConfigReferences: []addonv1beta1.DefaultConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1beta1.ConfigSpecHash{
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
InstallProgressions: []addonv1beta1.InstallProgression{
|
|
{
|
|
PlacementRef: addonv1beta1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
ConfigReferences: []addonv1beta1.InstallConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1beta1.ConfigSpecHash{
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: &internalv1alpha1.ClusterManagementAddOn{
|
|
ClusterManagementAddOn: addonv1alpha1.ClusterManagementAddOn{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "ClusterManagementAddOn",
|
|
APIVersion: "addon.open-cluster-management.io/v1alpha1",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-addon",
|
|
},
|
|
Spec: addonv1alpha1.ClusterManagementAddOnSpec{
|
|
AddOnMeta: addonv1alpha1.AddOnMeta{
|
|
DisplayName: "Test AddOn",
|
|
Description: "Test description",
|
|
},
|
|
SupportedConfigs: []addonv1alpha1.ConfigMeta{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DefaultConfig: &addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
InstallStrategy: addonv1alpha1.InstallStrategy{
|
|
Type: addonv1alpha1.AddonInstallStrategyPlacements,
|
|
Placements: []addonv1alpha1.PlacementStrategy{
|
|
{
|
|
PlacementRef: addonv1alpha1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
Configs: []addonv1alpha1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
RolloutStrategy: clusterv1alpha1.RolloutStrategy{
|
|
Type: clusterv1alpha1.All,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Status: addonv1alpha1.ClusterManagementAddOnStatus{
|
|
DefaultConfigReferences: []addonv1alpha1.DefaultConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
InstallProgressions: []addonv1alpha1.InstallProgression{
|
|
{
|
|
PlacementRef: addonv1alpha1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
ConfigReferences: []addonv1alpha1.InstallConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
dst := &internalv1alpha1.ClusterManagementAddOn{}
|
|
if err := tc.src.ConvertTo(dst); err != nil {
|
|
t.Fatalf("ConvertTo() failed: %v", err)
|
|
}
|
|
|
|
if diff := cmp.Diff(tc.expected, dst); diff != "" {
|
|
t.Errorf("ConvertTo() mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestClusterManagementAddOnConvertFrom(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
src *internalv1alpha1.ClusterManagementAddOn
|
|
expected *ClusterManagementAddOn
|
|
}{
|
|
{
|
|
name: "complete conversion with all fields",
|
|
src: &internalv1alpha1.ClusterManagementAddOn{
|
|
ClusterManagementAddOn: addonv1alpha1.ClusterManagementAddOn{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-addon",
|
|
},
|
|
Spec: addonv1alpha1.ClusterManagementAddOnSpec{
|
|
AddOnMeta: addonv1alpha1.AddOnMeta{
|
|
DisplayName: "Test AddOn",
|
|
Description: "Test description",
|
|
},
|
|
SupportedConfigs: []addonv1alpha1.ConfigMeta{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DefaultConfig: &addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
InstallStrategy: addonv1alpha1.InstallStrategy{
|
|
Type: addonv1alpha1.AddonInstallStrategyPlacements,
|
|
Placements: []addonv1alpha1.PlacementStrategy{
|
|
{
|
|
PlacementRef: addonv1alpha1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
Configs: []addonv1alpha1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
RolloutStrategy: clusterv1alpha1.RolloutStrategy{
|
|
Type: clusterv1alpha1.All,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Status: addonv1alpha1.ClusterManagementAddOnStatus{
|
|
DefaultConfigReferences: []addonv1alpha1.DefaultConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
InstallProgressions: []addonv1alpha1.InstallProgression{
|
|
{
|
|
PlacementRef: addonv1alpha1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
ConfigReferences: []addonv1alpha1.InstallConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
|
|
ConfigReferent: addonv1alpha1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
expected: &ClusterManagementAddOn{
|
|
ClusterManagementAddOn: addonv1beta1.ClusterManagementAddOn{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "ClusterManagementAddOn",
|
|
APIVersion: "addon.open-cluster-management.io/v1beta1",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "test-addon",
|
|
},
|
|
Spec: addonv1beta1.ClusterManagementAddOnSpec{
|
|
AddOnMeta: addonv1beta1.AddOnMeta{
|
|
DisplayName: "Test AddOn",
|
|
Description: "Test description",
|
|
},
|
|
DefaultConfigs: []addonv1beta1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
InstallStrategy: addonv1beta1.InstallStrategy{
|
|
Type: addonv1beta1.AddonInstallStrategyPlacements,
|
|
Placements: []addonv1beta1.PlacementStrategy{
|
|
{
|
|
PlacementRef: addonv1beta1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
Configs: []addonv1beta1.AddOnConfig{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
},
|
|
},
|
|
RolloutStrategy: clusterv1alpha1.RolloutStrategy{
|
|
Type: clusterv1alpha1.All,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Status: addonv1beta1.ClusterManagementAddOnStatus{
|
|
DefaultConfigReferences: []addonv1beta1.DefaultConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1beta1.ConfigSpecHash{
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
InstallProgressions: []addonv1beta1.InstallProgression{
|
|
{
|
|
PlacementRef: addonv1beta1.PlacementRef{
|
|
Name: "placement1",
|
|
Namespace: "default",
|
|
},
|
|
ConfigReferences: []addonv1beta1.InstallConfigReference{
|
|
{
|
|
ConfigGroupResource: addonv1beta1.ConfigGroupResource{
|
|
Group: "addon.open-cluster-management.io",
|
|
Resource: "addondeploymentconfigs",
|
|
},
|
|
DesiredConfig: &addonv1beta1.ConfigSpecHash{
|
|
ConfigReferent: addonv1beta1.ConfigReferent{
|
|
Name: "config1",
|
|
Namespace: "default",
|
|
},
|
|
SpecHash: "hash123",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
dst := &ClusterManagementAddOn{}
|
|
if err := dst.ConvertFrom(tc.src); err != nil {
|
|
t.Fatalf("ConvertFrom() failed: %v", err)
|
|
}
|
|
|
|
if diff := cmp.Diff(tc.expected, dst); diff != "" {
|
|
t.Errorf("ConvertFrom() mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|