Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ set agent install namespace from addon deployment config for template type addons #266

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
set agent install namespace from addon deployment config for template…
… type addons

Signed-off-by: zhujian <jiazhu@redhat.com>
  • Loading branch information
zhujian7 committed Sep 12, 2023
commit c524ca79b6b86872d1fc2f0b566ee8af4c77efb7
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ spec:
description: DeployOption contains the options of deploying a klusterlet
properties:
mode:
description: 'Mode can be Default, Hosted or Singleton. It is
Default mode if not specified In Default mode, all klusterlet
description: 'Mode can be Default, Hosted, Singleton or SingletonHosted.
It is Default mode if not specified In Default mode, all klusterlet
related resources are deployed on the managed cluster. In Hosted
mode, only crd and configurations are installed on the spoke/managed
cluster. Controllers run in another cluster (defined as management-cluster)
and connect to the mangaged cluster with the kubeconfig in secret
of "external-managed-kubeconfig"(a kubeconfig of managed-cluster
with cluster-admin permission). In Singleton mode, registration/work
agent is started as a single deployment. Note: Do not modify
the Mode field once it''s applied.'
agent is started as a single deployment. In SingletonHosted
mode, agent is started as a single deployment in hosted mode.
Note: Do not modify the Mode field once it''s applied.'
type: string
type: object
externalServerURLs:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
k8s.io/klog/v2 v2.90.1
k8s.io/kube-aggregator v0.27.2
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
open-cluster-management.io/addon-framework v0.7.1-0.20230803002113-eea76f8f5ad7
open-cluster-management.io/api v0.11.1-0.20230830071821-9675ab737d20
open-cluster-management.io/addon-framework v0.7.1-0.20230911140813-9676b4f8c180
open-cluster-management.io/api v0.11.1-0.20230905055724-cf1ead467a83
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/kube-storage-version-migrator v0.0.5
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749 h1:xMMXJlJbsU8w3V5N2FLDQ8YgU8s1EoULdbQBcAeNJkY=
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
open-cluster-management.io/addon-framework v0.7.1-0.20230803002113-eea76f8f5ad7 h1:GozqvUtekO4Zg90wLih3CA/ZYKLJlGKX+vL990U8DoQ=
open-cluster-management.io/addon-framework v0.7.1-0.20230803002113-eea76f8f5ad7/go.mod h1:gLGpXkdwAzzV+JB5eQPNHbZFJwp7HsKSSwgqOxGNVCw=
open-cluster-management.io/api v0.11.1-0.20230830071821-9675ab737d20 h1:R2aOyfax0T8LMofjAW5xQCQN+tEoxUiouHGK8SKFZz0=
open-cluster-management.io/api v0.11.1-0.20230830071821-9675ab737d20/go.mod h1:nsQ/G5JpfjQUg7dHpblyywWC6BRqklNaF6fIswVCHyY=
open-cluster-management.io/addon-framework v0.7.1-0.20230911140813-9676b4f8c180 h1:fEqGXqPJhBUSkeXXlJaAalX36F9NWRcv1pdbj2tYCfk=
open-cluster-management.io/addon-framework v0.7.1-0.20230911140813-9676b4f8c180/go.mod h1:8ESgg9EzyUZ2n5/Qgl8E2jnMmnd02YxXn92K5+Egedc=
open-cluster-management.io/api v0.11.1-0.20230905055724-cf1ead467a83 h1:3zbT3sT/tEAQbpjIk6uRiTQGknQ3kQlfd11ElVuXyyQ=
open-cluster-management.io/api v0.11.1-0.20230905055724-cf1ead467a83/go.mod h1:nsQ/G5JpfjQUg7dHpblyywWC6BRqklNaF6fIswVCHyY=
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
22 changes: 9 additions & 13 deletions pkg/addon/templateagent/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package templateagent

import (
"fmt"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"

Expand All @@ -11,27 +13,21 @@ import (
// AddonTemplateConfigRef return the first addon template config
func AddonTemplateConfigRef(
configReferences []addonapiv1alpha1.ConfigReference) (bool, addonapiv1alpha1.ConfigReference) {
for _, config := range configReferences {
if config.Group == utils.AddOnTemplateGVR.Group && config.Resource == utils.AddOnTemplateGVR.Resource {
return true, config
}
}
return false, addonapiv1alpha1.ConfigReference{}
return utils.GetAddOnConfigRef(configReferences, utils.AddOnTemplateGVR.Group, utils.AddOnTemplateGVR.Resource)
}

// GetTemplateSpecHash returns the sha256 hash of the spec field of the addon template
func GetTemplateSpecHash(template *addonapiv1alpha1.AddOnTemplate) (string, error) {
// GetAddOnTemplateSpecHash returns the sha256 hash of the spec field of the addon template
func GetAddOnTemplateSpecHash(template *addonapiv1alpha1.AddOnTemplate) (string, error) {
if template == nil {
return "", fmt.Errorf("addon template is nil")
}
unstructuredTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(template)
if err != nil {
return "", err
}
specHash, err := utils.GetSpecHash(&unstructured.Unstructured{
return utils.GetSpecHash(&unstructured.Unstructured{
Object: unstructuredTemplate,
})
if err != nil {
return specHash, err
}
return specHash, nil
}

// SupportAddOnTemplate return true if the given ClusterManagementAddOn supports the AddOnTemplate
Expand Down
60 changes: 60 additions & 0 deletions pkg/addon/templateagent/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package templateagent

import (
"testing"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
)

func TestGetAddOnTemplateSpecHash(t *testing.T) {
cases := []struct {
name string
at *addonapiv1alpha1.AddOnTemplate
expected string
expectedErr string
}{
{
name: "addon template is nil",
at: nil,
expected: "",
expectedErr: "addon template is nil",
},
{
name: "addon template spec is nil",
at: &addonapiv1alpha1.AddOnTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
},
Spec: addonapiv1alpha1.AddOnTemplateSpec{},
},
expected: "aa3e489402ac2e99c4aef0ddc8cc2fdf1d3b6c34c7b8d040dc3fae5db60478cb",
},
{
name: "addon template spec is not nil",
at: &addonapiv1alpha1.AddOnTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
},
Spec: addonapiv1alpha1.AddOnTemplateSpec{
AddonName: "test1",
},
},
expected: "00730aa8aa1826c9a3cfd8d6858b45e1e16bcdade5cc57070ea8089c6764285e",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
hash, err := GetAddOnTemplateSpecHash(c.at)
if c.expectedErr != "" {
assert.Equal(t, c.expectedErr, err.Error(), "should be equal")
} else {
assert.Nil(t, err, "should be nil")
}
assert.Equal(t, c.expected, hash, "should be equal")
})
}
}
2 changes: 2 additions & 0 deletions pkg/addon/templateagent/template_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func (a *CRDTemplateAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions {
PermissionConfig: a.TemplatePermissionConfigFunc(),
CSRApproveCheck: a.TemplateCSRApproveCheckFunc(),
CSRSign: a.TemplateCSRSignFunc(),
AgentInstallNamespace: utils.AgentInstallNamespaceFromDeploymentConfigFunc(
utils.NewAddOnDeploymentConfigGetter(a.addonClient)),
},
AgentDeployTriggerClusterFilter: utils.ClusterImageRegistriesAnnotationChanged,
}
Expand Down
Loading