Files
open-cluster-management/test/framework/managedclusteraddon.go
T
12c257987e 🌱 add v1beta1 e2e tests for addon API - preserve v1alpha1 tests (#1553)
* test: add v1beta1 e2e tests for addon lifecycle and install strategy

Add v1beta1 e2e test coverage following the alpha/beta split pattern from
integration tests. Rename framework helper functions to use explicit
V1Alpha1/V1Beta1 suffixes for consistency.

Framework changes (test/framework/managedclusteraddon.go):
- Rename CreateManagedClusterAddOn to CreateManagedClusterAddOnV1Alpha1
- Rename CheckManagedClusterAddOnStatus to CheckManagedClusterAddOnStatusV1Alpha1
- Add CheckManagedClusterAddOnStatusV1Beta1 helper
- Organize functions with Alpha version followed by Beta counterpart

E2E test changes:
- Rename addon_test.go to addon_alpha_test.go (v1alpha1 API)
- Create new addon_test.go with v1beta1 API using V1Beta1 helpers
- Rename addon_install_test.go to addon_install_alpha_test.go (v1alpha1 API)
- Create new addon_install_test.go with v1beta1 API
- Update addon_lease_test.go, addon_token_auth_test.go, addonmanagement_test.go
  to use V1Alpha1 helpers

Test coverage (both alpha and v1beta1):
- addon_test.go: Basic ManagedClusterAddOn lifecycle and availability
- addon_install_test.go: ClusterManagementAddOn with placement-based install
  strategy, addon annotation syncing

Naming pattern matches integration tests: *_alpha_test.go for v1alpha1,
*_test.go (no suffix) for v1beta1.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Tesshu Flower <tflower@redhat.com>

* test: add v1beta1 e2e tests for addon lease health check

Add v1beta1 e2e test coverage for addon lease-based health checking
following the alpha/beta split pattern.

Changes:
- Rename addon_lease_test.go to addon_lease_alpha_test.go (v1alpha1 API)
- Create new addon_lease_test.go with v1beta1 API using V1Beta1 helpers
- Update all AddonClient.AddonV1alpha1() calls to AddonV1beta1() in beta test

Both alpha and v1beta1 tests cover:
- Addon status remains available while lease is updated
- Addon status changes to unavailable when lease stops updating
- Addon status changes to unknown when no lease exists
- Addon status changes to unknown when managed cluster lease stops updating

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Tesshu Flower <tflower@redhat.com>

* test: migrate addon_token_auth test to alpha/beta versions

- Rename addon_token_auth_test.go to addon_token_auth_alpha_test.go
- Update alpha Describe to include (v1alpha1)
- Create new addon_token_auth_test.go for v1beta1
- Update imports and client calls to use v1beta1 API

Signed-off-by: Tesshu Flower <tflower@redhat.com>

---------

Signed-off-by: Tesshu Flower <tflower@redhat.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-06-04 02:06:45 +00:00

178 lines
6.1 KiB
Go

package framework
import (
"context"
"fmt"
"time"
coordv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1beta1 "open-cluster-management.io/api/addon/v1beta1"
)
// CreateManagedClusterAddOnV1Alpha1 creates a ManagedClusterAddOn using v1alpha1 API
func (hub *Hub) CreateManagedClusterAddOnV1Alpha1(managedClusterNamespace, addOnName, installNamespace string) error {
_, err := hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(managedClusterNamespace).Create(
context.TODO(),
&addonv1alpha1.ManagedClusterAddOn{
ObjectMeta: metav1.ObjectMeta{
Namespace: managedClusterNamespace,
Name: addOnName,
},
Spec: addonv1alpha1.ManagedClusterAddOnSpec{},
},
metav1.CreateOptions{},
)
if err != nil {
return err
}
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
addOn, err := hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(managedClusterNamespace).Get(
context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return err
}
if addOn.Status.Namespace == installNamespace {
return nil
}
addOn.Status.Namespace = installNamespace
_, err = hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(managedClusterNamespace).UpdateStatus(
context.TODO(), addOn, metav1.UpdateOptions{})
return err
})
}
func (hub *Hub) CreateManagedClusterAddOnLease(addOnInstallNamespace, addOnName string) error {
if _, err := hub.KubeClient.CoreV1().Namespaces().Create(
context.TODO(),
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: addOnInstallNamespace,
},
},
metav1.CreateOptions{},
); err != nil {
return err
}
_, err := hub.KubeClient.CoordinationV1().Leases(addOnInstallNamespace).Create(
context.TODO(),
&coordv1.Lease{
ObjectMeta: metav1.ObjectMeta{
Name: addOnName,
Namespace: addOnInstallNamespace,
},
Spec: coordv1.LeaseSpec{
RenewTime: &metav1.MicroTime{Time: time.Now()},
},
},
metav1.CreateOptions{},
)
return err
}
// CheckManagedClusterAddOnStatusV1Alpha1 checks the status of a ManagedClusterAddOn using v1alpha1 API
func (hub *Hub) CheckManagedClusterAddOnStatusV1Alpha1(managedClusterNamespace, addOnName string) error {
addOn, err := hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(managedClusterNamespace).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return err
}
if addOn.Status.Conditions == nil {
return fmt.Errorf("there is no conditions in addon %v/%v", managedClusterNamespace, addOnName)
}
if !meta.IsStatusConditionTrue(addOn.Status.Conditions, "Available") {
return fmt.Errorf("the addon %v/%v available condition is not true, %v",
managedClusterNamespace, addOnName, addOn.Status.Conditions)
}
return nil
}
// CheckManagedClusterAddOnStatusV1Beta1 checks the status of a ManagedClusterAddOn using v1beta1 API
func (hub *Hub) CheckManagedClusterAddOnStatusV1Beta1(managedClusterNamespace, addOnName string) error {
addOn, err := hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(managedClusterNamespace).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return err
}
if addOn.Status.Conditions == nil {
return fmt.Errorf("there is no conditions in addon %v/%v", managedClusterNamespace, addOnName)
}
if !meta.IsStatusConditionTrue(addOn.Status.Conditions, "Available") {
return fmt.Errorf("the addon %v/%v available condition is not true, %v",
managedClusterNamespace, addOnName, addOn.Status.Conditions)
}
return nil
}
// CreateManagedClusterAddOnV1Beta1 creates a ManagedClusterAddOn using v1beta1 API
func (hub *Hub) CreateManagedClusterAddOnV1Beta1(managedClusterNamespace, addOnName, installNamespace string) error {
_, err := hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(managedClusterNamespace).Create(
context.TODO(),
&addonv1beta1.ManagedClusterAddOn{
ObjectMeta: metav1.ObjectMeta{
Namespace: managedClusterNamespace,
Name: addOnName,
},
Spec: addonv1beta1.ManagedClusterAddOnSpec{},
},
metav1.CreateOptions{},
)
if err != nil {
return err
}
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
addOn, err := hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(managedClusterNamespace).Get(
context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return err
}
if addOn.Status.Namespace == installNamespace {
return nil
}
addOn.Status.Namespace = installNamespace
_, err = hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(managedClusterNamespace).UpdateStatus(
context.TODO(), addOn, metav1.UpdateOptions{})
return err
})
}
// GetManagedClusterAddOnV1Beta1 gets a ManagedClusterAddOn using v1beta1 API
func (hub *Hub) GetManagedClusterAddOnV1Beta1(managedClusterNamespace, addOnName string) (*addonv1beta1.ManagedClusterAddOn, error) {
return hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(managedClusterNamespace).Get(
context.TODO(), addOnName, metav1.GetOptions{})
}
// UpdateManagedClusterAddOnV1Beta1 updates a ManagedClusterAddOn using v1beta1 API
func (hub *Hub) UpdateManagedClusterAddOnV1Beta1(addon *addonv1beta1.ManagedClusterAddOn) (*addonv1beta1.ManagedClusterAddOn, error) {
return hub.AddonClient.AddonV1beta1().ManagedClusterAddOns(addon.Namespace).Update(
context.TODO(), addon, metav1.UpdateOptions{})
}
// GetManagedClusterAddOnV1Alpha1 gets a ManagedClusterAddOn using v1alpha1 API
func (hub *Hub) GetManagedClusterAddOnV1Alpha1(managedClusterNamespace, addOnName string) (*addonv1alpha1.ManagedClusterAddOn, error) {
return hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(managedClusterNamespace).Get(
context.TODO(), addOnName, metav1.GetOptions{})
}
// UpdateManagedClusterAddOnV1Alpha1 updates a ManagedClusterAddOn using v1alpha1 API
func (hub *Hub) UpdateManagedClusterAddOnV1Alpha1(addon *addonv1alpha1.ManagedClusterAddOn) (*addonv1alpha1.ManagedClusterAddOn, error) {
return hub.AddonClient.AddonV1alpha1().ManagedClusterAddOns(addon.Namespace).Update(
context.TODO(), addon, metav1.UpdateOptions{})
}