Skip to content

Commit

Permalink
upgrade ocm api
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <jiazhu@redhat.com>
  • Loading branch information
zhujian7 committed Jul 27, 2023
1 parent 4f8c933 commit 4a572be
Show file tree
Hide file tree
Showing 17 changed files with 628 additions and 38 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
k8s.io/component-base v0.26.1
k8s.io/klog/v2 v2.80.1
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139
open-cluster-management.io/api v0.11.1-0.20230727093131-915f5826cff9
sigs.k8s.io/controller-runtime v0.14.4
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139 h1:nw/XSv4eDGqmg0ks2PHzrE2uosvjw+D314843G56xGY=
open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139/go.mod h1:WgKUCJ7+Bf40DsOmH1Gdkpyj3joco+QLzrlM6Ak39zE=
open-cluster-management.io/api v0.11.1-0.20230727093131-915f5826cff9 h1:P5yjl8w09JYsTE1D6JV6y1vY9X2bBN8m494ZYg9HoyY=
open-cluster-management.io/api v0.11.1-0.20230727093131-915f5826cff9/go.mod h1:WgKUCJ7+Bf40DsOmH1Gdkpyj3joco+QLzrlM6Ak39zE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
10 changes: 4 additions & 6 deletions pkg/addonfactory/addondeploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ func getRegistriesFromClusterAnnotation(
return nil, nil
}
annotations := cluster.GetAnnotations()
klog.V(4).Infof("Try to get image registries from annotation %v", annotations[ClusterImageRegistriesAnnotation])
if len(annotations[ClusterImageRegistriesAnnotation]) == 0 {
klog.V(4).Infof("Try to get image registries from annotation %v", annotations[clusterv1.ClusterImageRegistriesAnnotationKey])
if len(annotations[clusterv1.ClusterImageRegistriesAnnotationKey]) == 0 {
return nil, nil
}
type ImageRegistries struct {
Registries []addonapiv1alpha1.ImageMirror `json:"registries"`
}

imageRegistries := ImageRegistries{}
err := json.Unmarshal([]byte(annotations[ClusterImageRegistriesAnnotation]), &imageRegistries)
err := json.Unmarshal([]byte(annotations[clusterv1.ClusterImageRegistriesAnnotationKey]), &imageRegistries)
if err != nil {
klog.Errorf("failed to unmarshal the annotation %v, err %v", annotations[ClusterImageRegistriesAnnotation], err)
klog.Errorf("failed to unmarshal the annotation %v, err %v", annotations[clusterv1.ClusterImageRegistriesAnnotationKey], err)
return nil, err
}
return imageRegistries.Registries, nil
Expand Down Expand Up @@ -383,8 +383,6 @@ func overrideImageWithKeyValue(imageKey, image string, getRegistries func() ([]a
return nestedMap, overrode, nil
}

const ClusterImageRegistriesAnnotation = "open-cluster-management.io/image-registries"

// OverrideImage checks whether the source configured in registries can match the imagedName, if yes will use the
// mirror value in the registries to override the imageName
func OverrideImage(registries []addonapiv1alpha1.ImageMirror, imageName string) string {
Expand Down
16 changes: 8 additions & 8 deletions pkg/addonfactory/addondeploymentconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x/y","source":"a/b"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x/y","source":"a/b"}]}`,
},
},
},
Expand All @@ -404,7 +404,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x","source":"a"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x","source":"a"}]}`,
},
},
},
Expand All @@ -423,7 +423,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x","source":"a"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x","source":"a"}]}`,
},
},
},
Expand All @@ -436,7 +436,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x","source":"a"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x","source":"a"}]}`,
},
},
},
Expand All @@ -449,7 +449,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x","source":"b"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x","source":"b"}]}`,
},
},
},
Expand All @@ -468,7 +468,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"y"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"y"}]}`,
},
},
},
Expand All @@ -487,7 +487,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":`,
},
},
},
Expand All @@ -506,7 +506,7 @@ func TestGetAgentImageValues(t *testing.T) {
cluster: &clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
ClusterImageRegistriesAnnotation: `{"registries":[{"mirror":"x","source":"a"}]}`,
clusterv1.ClusterImageRegistriesAnnotationKey: `{"registries":[{"mirror":"x","source":"a"}]}`,
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/helloworld_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
clusterv1 "open-cluster-management.io/api/cluster/v1"
)

const (
Expand Down Expand Up @@ -350,7 +351,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
if annotations == nil {
annotations = make(map[string]string)
}
annotations["open-cluster-management.io/image-registries"] = string(registriesJson)
annotations[clusterv1.ClusterImageRegistriesAnnotationKey] = string(registriesJson)

newCluster.Annotations = annotations
_, err = hubClusterClient.ClusterV1().ManagedClusters().Update(
Expand Down Expand Up @@ -421,7 +422,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
}

newCluster := cluster.DeepCopy()
delete(newCluster.Annotations, "open-cluster-management.io/image-registries")
delete(newCluster.Annotations, clusterv1.ClusterImageRegistriesAnnotationKey)
_, err = hubClusterClient.ClusterV1().ManagedClusters().Update(
context.Background(), newCluster, metav1.UpdateOptions{})
return err
Expand All @@ -448,7 +449,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
if annotations == nil {
annotations = make(map[string]string)
}
annotations["open-cluster-management.io/image-registries"] = string(registriesJson)
annotations[clusterv1.ClusterImageRegistriesAnnotationKey] = string(registriesJson)

newCluster.Annotations = annotations
_, err = hubClusterClient.ClusterV1().ManagedClusters().Update(
Expand Down Expand Up @@ -510,7 +511,7 @@ var _ = ginkgo.Describe("install/uninstall helloworld helm addons", func() {
}

newCluster := cluster.DeepCopy()
delete(newCluster.Annotations, "open-cluster-management.io/image-registries")
delete(newCluster.Annotations, clusterv1.ClusterImageRegistriesAnnotationKey)
_, err = hubClusterClient.ClusterV1().ManagedClusters().Update(
context.Background(), newCluster, metav1.UpdateOptions{})
return err
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/strings/slices
k8s.io/utils/trace
# open-cluster-management.io/api v0.11.1-0.20230609103311-088e8fe86139
# open-cluster-management.io/api v0.11.1-0.20230727093131-915f5826cff9
## explicit; go 1.19
open-cluster-management.io/api/addon/v1alpha1
open-cluster-management.io/api/client/addon/clientset/versioned
Expand Down

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

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

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

17 changes: 17 additions & 0 deletions vendor/open-cluster-management.io/api/cluster/v1/types.go

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

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

Loading

0 comments on commit 4a572be

Please sign in to comment.