Skip to content

Commit db39f1b

Browse files
committed
🌱 upgrade add-on APIs to v1beta1
Signed-off-by: Yang Le <[email protected]>
1 parent b5846d7 commit db39f1b

File tree

79 files changed

+1878
-1406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1878
-1406
lines changed

‎cmd/example/helloworld/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
utilflag "k8s.io/component-base/cli/flag"
1616
logs "k8s.io/component-base/logs/api/v1"
1717
"k8s.io/klog/v2"
18-
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
18+
addonv1beta1client "open-cluster-management.io/api/client/addon/clientset/versioned"
1919

2020
"open-cluster-management.io/addon-framework/examples/helloworld"
2121
"open-cluster-management.io/addon-framework/examples/helloworld_agent"
@@ -85,7 +85,7 @@ type addManagerConfig struct {
8585
}
8686

8787
func (c *addManagerConfig) runController(ctx context.Context, kubeConfig *rest.Config) error {
88-
addonClient, err := addonv1alpha1client.NewForConfig(kubeConfig)
88+
addonClient, err := addonv1beta1client.NewForConfig(kubeConfig)
8989
if err != nil {
9090
return err
9191
}

‎cmd/example/helloworld_helm/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
utilflag "k8s.io/component-base/cli/flag"
1818
logs "k8s.io/component-base/logs/api/v1"
1919
"k8s.io/klog/v2"
20-
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
20+
addonv1beta1client "open-cluster-management.io/api/client/addon/clientset/versioned"
2121

2222
"open-cluster-management.io/addon-framework/examples/helloworld"
2323
"open-cluster-management.io/addon-framework/examples/helloworld_agent"
@@ -84,7 +84,7 @@ func runController(ctx context.Context, kubeConfig *rest.Config) error {
8484
return err
8585
}
8686

87-
addonClient, err := addonv1alpha1client.NewForConfig(kubeConfig)
87+
addonClient, err := addonv1beta1client.NewForConfig(kubeConfig)
8888
if err != nil {
8989
return err
9090
}

‎examples/helloworld/helloworld.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"open-cluster-management.io/addon-framework/pkg/addonfactory"
1111
"open-cluster-management.io/addon-framework/pkg/agent"
1212
"open-cluster-management.io/addon-framework/pkg/utils"
13-
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
13+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
1414
clusterv1 "open-cluster-management.io/api/cluster/v1"
1515
)
1616

@@ -33,7 +33,7 @@ func NewRegistrationOption(kubeConfig *rest.Config, addonName, agentName string)
3333
}
3434

3535
func GetDefaultValues(cluster *clusterv1.ManagedCluster,
36-
addon *addonapiv1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
36+
addon *addonapiv1beta1.ManagedClusterAddOn) (addonfactory.Values, error) {
3737

3838
image := os.Getenv("EXAMPLE_IMAGE_NAME")
3939
if len(image) == 0 {

‎examples/helloworld/helloworld_test.go‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
utilrand "k8s.io/apimachinery/pkg/util/rand"
1212
"k8s.io/klog/v2"
1313
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
14+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
1415
fakeaddon "open-cluster-management.io/api/client/addon/clientset/versioned/fake"
1516
clusterv1 "open-cluster-management.io/api/cluster/v1"
1617

@@ -28,7 +29,7 @@ func TestManifestAddonAgent(t *testing.T) {
2829
cases := []struct {
2930
name string
3031
managedCluster *clusterv1.ManagedCluster
31-
managedClusterAddOn *addonapiv1alpha1.ManagedClusterAddOn
32+
managedClusterAddOn *addonapiv1beta1.ManagedClusterAddOn
3233
configs []runtime.Object
3334
verifyDeployment func(t *testing.T, objs []runtime.Object)
3435
}{
@@ -59,7 +60,7 @@ func TestManifestAddonAgent(t *testing.T) {
5960
{
6061
name: "override image with annotation",
6162
managedCluster: addontesting.NewManagedCluster("cluster1"),
62-
managedClusterAddOn: func() *addonapiv1alpha1.ManagedClusterAddOn {
63+
managedClusterAddOn: func() *addonapiv1beta1.ManagedClusterAddOn {
6364
addon := addontesting.NewAddon("test", "cluster1")
6465
addon.Annotations = map[string]string{
6566
"addon.open-cluster-management.io/values": `{"Image":"quay.io/test:test"}`}
@@ -88,20 +89,16 @@ func TestManifestAddonAgent(t *testing.T) {
8889
{
8990
name: "with addon deployment config",
9091
managedCluster: addontesting.NewManagedCluster("cluster1"),
91-
managedClusterAddOn: func() *addonapiv1alpha1.ManagedClusterAddOn {
92+
managedClusterAddOn: func() *addonapiv1beta1.ManagedClusterAddOn {
9293
addon := addontesting.NewAddon("test", "cluster1")
93-
addon.Status.ConfigReferences = []addonapiv1alpha1.ConfigReference{
94+
addon.Status.ConfigReferences = []addonapiv1beta1.ConfigReference{
9495
{
95-
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
96+
ConfigGroupResource: addonapiv1beta1.ConfigGroupResource{
9697
Group: "addon.open-cluster-management.io",
9798
Resource: "addondeploymentconfigs",
9899
},
99-
ConfigReferent: addonapiv1alpha1.ConfigReferent{
100-
Namespace: "cluster1",
101-
Name: "config",
102-
},
103-
DesiredConfig: &addonapiv1alpha1.ConfigSpecHash{
104-
ConfigReferent: addonapiv1alpha1.ConfigReferent{
100+
DesiredConfig: &addonapiv1beta1.ConfigSpecHash{
101+
ConfigReferent: addonapiv1beta1.ConfigReferent{
105102
Namespace: "cluster1",
106103
Name: "config",
107104
},

‎examples/helloworld_agent/agent.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
cmdfactory "open-cluster-management.io/addon-framework/pkg/cmd/factory"
2222
"open-cluster-management.io/addon-framework/pkg/lease"
2323
"open-cluster-management.io/addon-framework/pkg/version"
24-
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
24+
addonv1beta1client "open-cluster-management.io/api/client/addon/clientset/versioned"
2525
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
2626
)
2727

@@ -93,7 +93,7 @@ func (o *AgentOptions) RunAgent(ctx context.Context, kubeconfig *rest.Config) er
9393
if err != nil {
9494
return err
9595
}
96-
addonClient, err := addonv1alpha1client.NewForConfig(hubRestConfig)
96+
addonClient, err := addonv1beta1client.NewForConfig(hubRestConfig)
9797
if err != nil {
9898
return err
9999
}
@@ -125,7 +125,7 @@ func (o *AgentOptions) RunAgent(ctx context.Context, kubeconfig *rest.Config) er
125125

126126
type agentController struct {
127127
spokeKubeClient kubernetes.Interface
128-
addonClient addonv1alpha1client.Interface
128+
addonClient addonv1beta1client.Interface
129129
hubConfigMapLister corev1lister.ConfigMapLister
130130
clusterName string
131131
addonName string
@@ -134,7 +134,7 @@ type agentController struct {
134134

135135
func newAgentController(
136136
spokeKubeClient kubernetes.Interface,
137-
addonClient addonv1alpha1client.Interface,
137+
addonClient addonv1beta1client.Interface,
138138
configmapInformers corev1informers.ConfigMapInformer,
139139
clusterName string,
140140
addonName string,
@@ -173,7 +173,7 @@ func (c *agentController) sync(ctx context.Context, syncCtx factory.SyncContext,
173173
return err
174174
}
175175

176-
addon, err := c.addonClient.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(ctx, c.addonName, metav1.GetOptions{})
176+
addon, err := c.addonClient.AddonV1beta1().ManagedClusterAddOns(clusterName).Get(ctx, c.addonName, metav1.GetOptions{})
177177
if err != nil {
178178
return err
179179
}

‎examples/helloworld_helm/helloworld_helm.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"k8s.io/client-go/kubernetes"
1111
"open-cluster-management.io/addon-framework/pkg/addonfactory"
1212
"open-cluster-management.io/addon-framework/pkg/agent"
13-
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
13+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
1414
clusterv1 "open-cluster-management.io/api/cluster/v1"
1515
workapiv1 "open-cluster-management.io/api/work/v1"
1616
)
@@ -41,7 +41,7 @@ type userValues struct {
4141
}
4242

4343
func GetDefaultValues(cluster *clusterv1.ManagedCluster,
44-
addon *addonapiv1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
44+
addon *addonapiv1beta1.ManagedClusterAddOn) (addonfactory.Values, error) {
4545
image := os.Getenv("EXAMPLE_IMAGE_NAME")
4646
if len(image) == 0 {
4747
image = defaultImage
@@ -66,7 +66,7 @@ func GetDefaultValues(cluster *clusterv1.ManagedCluster,
6666
func GetImageValues(kubeClient kubernetes.Interface) addonfactory.GetValuesFunc {
6767
return func(
6868
cluster *clusterv1.ManagedCluster,
69-
addon *addonapiv1alpha1.ManagedClusterAddOn,
69+
addon *addonapiv1beta1.ManagedClusterAddOn,
7070
) (addonfactory.Values, error) {
7171
overrideValues := addonfactory.Values{}
7272
for _, config := range addon.Status.ConfigReferences {
@@ -88,12 +88,12 @@ func GetImageValues(kubeClient kubernetes.Interface) addonfactory.GetValuesFunc
8888

8989
image, ok := configMap.Data["image"]
9090
if !ok {
91-
return nil, fmt.Errorf("no image in configmap %s/%s", config.Namespace, config.Name)
91+
return nil, fmt.Errorf("no image in configmap %s/%s", config.DesiredConfig.Namespace, config.DesiredConfig.Name)
9292
}
9393

9494
imagePullPolicy, ok := configMap.Data["imagePullPolicy"]
9595
if !ok {
96-
return nil, fmt.Errorf("no imagePullPolicy in configmap %s/%s", config.Namespace, config.Name)
96+
return nil, fmt.Errorf("no imagePullPolicy in configmap %s/%s", config.DesiredConfig.Namespace, config.DesiredConfig.Name)
9797
}
9898

9999
userJsonValues := userValues{
@@ -135,7 +135,7 @@ func AgentHealthProber() *agent.HealthProber {
135135
},
136136
},
137137
HealthChecker: func(fields []agent.FieldResult, cluster *clusterv1.ManagedCluster,
138-
addon *addonapiv1alpha1.ManagedClusterAddOn) error {
138+
addon *addonapiv1beta1.ManagedClusterAddOn) error {
139139
if len(fields) == 0 {
140140
return fmt.Errorf("no fields found in health checker")
141141
}

‎examples/helloworld_helm/helloworld_helm_test.go‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
fakekube "k8s.io/client-go/kubernetes/fake"
1212
"k8s.io/klog/v2"
1313
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
14+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
1415
fakeaddon "open-cluster-management.io/api/client/addon/clientset/versioned/fake"
1516
clusterv1 "open-cluster-management.io/api/cluster/v1"
1617

@@ -34,7 +35,7 @@ func TestManifestAddonAgent(t *testing.T) {
3435
cases := []struct {
3536
name string
3637
managedCluster *clusterv1.ManagedCluster
37-
managedClusterAddOn *addonapiv1alpha1.ManagedClusterAddOn
38+
managedClusterAddOn *addonapiv1beta1.ManagedClusterAddOn
3839
configMaps []runtime.Object
3940
addOnDeploymentConfigs []runtime.Object
4041
verifyDeployment func(t *testing.T, objs []runtime.Object)
@@ -67,33 +68,31 @@ func TestManifestAddonAgent(t *testing.T) {
6768
{
6869
name: "with image config, addon deployment config and annotation",
6970
managedCluster: addontesting.NewManagedCluster("cluster1"),
70-
managedClusterAddOn: func() *addonapiv1alpha1.ManagedClusterAddOn {
71+
managedClusterAddOn: func() *addonapiv1beta1.ManagedClusterAddOn {
7172
addon := addontesting.NewAddon("test", "cluster1")
7273
addon.SetAnnotations(map[string]string{
7374
"addon.open-cluster-management.io/values": `{"global":{"imagePullSecret":"test-pull-secret","imagePullPolicy":"Never"}}`,
7475
})
75-
addon.Status.ConfigReferences = []addonapiv1alpha1.ConfigReference{
76+
addon.Status.ConfigReferences = []addonapiv1beta1.ConfigReference{
7677
{
77-
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
78+
ConfigGroupResource: addonapiv1beta1.ConfigGroupResource{
7879
Group: "",
7980
Resource: "configmaps",
8081
},
81-
ConfigReferent: addonapiv1alpha1.ConfigReferent{
82-
Namespace: "cluster1",
83-
Name: "image-config",
82+
DesiredConfig: &addonapiv1beta1.ConfigSpecHash{
83+
ConfigReferent: addonapiv1beta1.ConfigReferent{
84+
Namespace: "cluster1",
85+
Name: "image-config",
86+
},
8487
},
8588
},
8689
{
87-
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{
90+
ConfigGroupResource: addonapiv1beta1.ConfigGroupResource{
8891
Group: "addon.open-cluster-management.io",
8992
Resource: "addondeploymentconfigs",
9093
},
91-
ConfigReferent: addonapiv1alpha1.ConfigReferent{
92-
Namespace: "cluster1",
93-
Name: "deploy-config",
94-
},
95-
DesiredConfig: &addonapiv1alpha1.ConfigSpecHash{
96-
ConfigReferent: addonapiv1alpha1.ConfigReferent{
94+
DesiredConfig: &addonapiv1beta1.ConfigSpecHash{
95+
ConfigReferent: addonapiv1beta1.ConfigReferent{
9796
Namespace: "cluster1",
9897
Name: "deploy-config",
9998
},

‎examples/rbac/rbac.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"k8s.io/client-go/kubernetes"
1111
"k8s.io/client-go/rest"
1212
"open-cluster-management.io/addon-framework/pkg/agent"
13-
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
13+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
1414
clusterv1 "open-cluster-management.io/api/cluster/v1"
1515
)
1616

1717
func AddonRBAC(kubeConfig *rest.Config) agent.PermissionConfigFunc {
18-
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1alpha1.ManagedClusterAddOn) error {
18+
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1beta1.ManagedClusterAddOn) error {
1919
kubeclient, err := kubernetes.NewForConfig(kubeConfig)
2020
if err != nil {
2121
return err

‎pkg/addonfactory/addondeploymentconfig.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"k8s.io/apimachinery/pkg/runtime/schema"
1010
"k8s.io/klog/v2"
1111
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
12-
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
12+
addonapiv1beta1 "open-cluster-management.io/api/addon/v1beta1"
13+
addonv1beta1client "open-cluster-management.io/api/client/addon/clientset/versioned"
1314
clusterv1 "open-cluster-management.io/api/cluster/v1"
1415

1516
"open-cluster-management.io/addon-framework/pkg/utils"
@@ -191,7 +192,7 @@ type AddOnDeploymentConfigToValuesFunc func(config addonapiv1alpha1.AddOnDeploym
191192

192193
// NewAddOnDeploymentConfigGetter returns a AddOnDeploymentConfigGetter with addon client
193194
// Deprecated: use NewAddOnDeploymentConfigGetter in pkg/utils package instead.
194-
func NewAddOnDeploymentConfigGetter(addonClient addonv1alpha1client.Interface) utils.AddOnDeploymentConfigGetter {
195+
func NewAddOnDeploymentConfigGetter(addonClient addonv1beta1client.Interface) utils.AddOnDeploymentConfigGetter {
195196
return utils.NewAddOnDeploymentConfigGetter(addonClient)
196197
}
197198

@@ -201,7 +202,7 @@ func NewAddOnDeploymentConfigGetter(addonClient addonv1alpha1client.Interface) u
201202
// override the one from small index
202203
func GetAddOnDeploymentConfigValues(
203204
getter utils.AddOnDeploymentConfigGetter, toValuesFuncs ...AddOnDeploymentConfigToValuesFunc) GetValuesFunc {
204-
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1alpha1.ManagedClusterAddOn) (Values, error) {
205+
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1beta1.ManagedClusterAddOn) (Values, error) {
205206
var lastValues = Values{}
206207
addOnDeploymentConfig, err := utils.GetDesiredAddOnDeploymentConfig(addon, getter)
207208
if err != nil {
@@ -382,7 +383,7 @@ func getRegistriesFromClusterAnnotation(
382383
// will be: {"global": {"imageOverrides": {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}}}
383384
// - Image registries configured in the addonDeploymentConfig will take precedence over the managed cluster annotation
384385
func GetAgentImageValues(getter utils.AddOnDeploymentConfigGetter, imageKey, image string) GetValuesFunc {
385-
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1alpha1.ManagedClusterAddOn) (Values, error) {
386+
return func(cluster *clusterv1.ManagedCluster, addon *addonapiv1beta1.ManagedClusterAddOn) (Values, error) {
386387
addOnDeploymentConfig, err := utils.GetDesiredAddOnDeploymentConfig(addon, getter)
387388
if err != nil {
388389
return nil, err

0 commit comments

Comments
 (0)