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

🌱 use DeploymentAvailability to check addon health #212

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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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.20230626092851-963716af4eed
open-cluster-management.io/addon-framework v0.7.1-0.20230705031704-6a328fa5cd63
open-cluster-management.io/api v0.11.1-0.20230703133341-6d7212c2e941
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/kube-storage-version-migrator v0.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,8 @@ 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.20230626092851-963716af4eed h1:fOOKf8kzVNizc5fYvMwkPy9TT/vOpojd4IIxpzh/vhw=
open-cluster-management.io/addon-framework v0.7.1-0.20230626092851-963716af4eed/go.mod h1:Cyt5knxR+sXaKvOfUKseZDAGulS2AJz6o7a9J0WXbak=
open-cluster-management.io/addon-framework v0.7.1-0.20230705031704-6a328fa5cd63 h1:GCsAD1jb6wqhXTHdUM/HcWzv5b2NbZ6FxpLZcxa/jhI=
open-cluster-management.io/addon-framework v0.7.1-0.20230705031704-6a328fa5cd63/go.mod h1:V+WUFC7GD89Lc68eXSN/FJebnCH4NjrfF44VsO0YAC8=
open-cluster-management.io/api v0.11.1-0.20230703133341-6d7212c2e941 h1:k10Sx7Th1UDyJ+GYFqWddFq+m6U7x9MHk1g8KwrYy8Y=
open-cluster-management.io/api v0.11.1-0.20230703133341-6d7212c2e941/go.mod h1:WgKUCJ7+Bf40DsOmH1Gdkpyj3joco+QLzrlM6Ak39zE=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
1 change: 1 addition & 0 deletions pkg/addon/controllers/addontemplate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (c *addonTemplateController) stopUnusedManagers(
stopFunc, ok := c.addonManagers[addOnName]
if ok {
stopFunc()
delete(c.addonManagers, addOnName)
klog.Infof("Stop the manager for addon %s", addOnName)
}
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/addon/controllers/addontemplate/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"time"

"github.com/openshift/library-go/pkg/operator/events/eventstesting"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic/dynamicinformer"
dynamicfake "k8s.io/client-go/dynamic/fake"
fakekube "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"

"open-cluster-management.io/addon-framework/pkg/addonmanager/addontesting"
"open-cluster-management.io/addon-framework/pkg/utils"
Expand Down Expand Up @@ -215,3 +217,52 @@ func TestReconcile(t *testing.T) {
}
}
}

func TestRunController(t *testing.T) {
cases := []struct {
name string
addonName string
expectedErr string
}{
{
name: "addon name empty",
addonName: "",
expectedErr: "addon name should be set",
},
{
name: "fake kubeconfig",
addonName: "test",
expectedErr: `Get "http://localhost/api": dial tcp [::1]:80: connect: connection refused`,
},
}

for _, c := range cases {
fakeAddonClient := fakeaddon.NewSimpleClientset()
addonInformers := addoninformers.NewSharedInformerFactory(fakeAddonClient, 10*time.Minute)
fakeDynamicClient := dynamicfake.NewSimpleDynamicClient(runtime.NewScheme())
dynamicInformerFactory := dynamicinformer.NewDynamicSharedInformerFactory(fakeDynamicClient, 0)
fakeClusterClient := fakecluster.NewSimpleClientset()
clusterInformers := clusterv1informers.NewSharedInformerFactory(fakeClusterClient, 10*time.Minute)
fakeWorkClient := fakework.NewSimpleClientset()
workInformers := workinformers.NewSharedInformerFactory(fakeWorkClient, 10*time.Minute)
hubKubeClient := fakekube.NewSimpleClientset()
controller := &addonTemplateController{
kubeConfig: &rest.Config{},
kubeClient: hubKubeClient,
addonClient: fakeAddonClient,
cmaLister: addonInformers.Addon().V1alpha1().ClusterManagementAddOns().Lister(),
addonManagers: make(map[string]context.CancelFunc),
addonInformers: addonInformers,
clusterInformers: clusterInformers,
dynamicInformers: dynamicInformerFactory,
workInformers: workInformers,
}
ctx := context.TODO()

err := controller.runController(ctx, c.addonName)
if len(c.expectedErr) == 0 {
assert.NoError(t, err)
}
assert.EqualErrorf(t, err, c.expectedErr, "name : %s, expected error %v, but got %v", c.name, c.expectedErr, err)
}
}
31 changes: 6 additions & 25 deletions pkg/addon/templateagent/template_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/valyala/fasttemplate"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -105,9 +104,11 @@ func (a *CRDTemplateAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions {
supportedConfigGVRs = append(supportedConfigGVRs, gvr)
}
return agent.AgentAddonOptions{
AddonName: a.addonName,
InstallStrategy: nil,
HealthProber: nil,
AddonName: a.addonName,
InstallStrategy: nil,
HealthProber: &agent.HealthProber{
Type: agent.HealthProberTypeDeploymentAvailability,
},
SupportedConfigGVRs: supportedConfigGVRs,
Registration: &agent.RegistrationOption{
CSRConfigurations: a.TemplateCSRConfigurationsFunc(),
Expand Down Expand Up @@ -159,7 +160,7 @@ func (a *CRDTemplateAgentAddon) decorateObjects(
newImageDecorator(privateValues),
}
for index, obj := range objects {
deployment, err := a.convertToDeployment(obj)
deployment, err := utils.ConvertToDeployment(obj)
if err != nil {
continue
}
Expand All @@ -176,26 +177,6 @@ func (a *CRDTemplateAgentAddon) decorateObjects(
return objects, nil
}

func (a *CRDTemplateAgentAddon) convertToDeployment(obj runtime.Object) (*appsv1.Deployment, error) {
if obj.GetObjectKind().GroupVersionKind().Group != "apps" ||
obj.GetObjectKind().GroupVersionKind().Kind != "Deployment" {
return nil, fmt.Errorf("not deployment object, %v", obj.GetObjectKind())
}

deployment := &appsv1.Deployment{}
uobj, ok := obj.(*unstructured.Unstructured)
if !ok {
return deployment, fmt.Errorf("not unstructured object, %v", obj.GetObjectKind())
}

err := runtime.DefaultUnstructuredConverter.
FromUnstructured(uobj.Object, deployment)
if err != nil {
return nil, err
}
return deployment, nil
}

// GetDesiredAddOnTemplateByAddon returns the desired template of the addon
func (a *CRDTemplateAgentAddon) GetDesiredAddOnTemplateByAddon(
addon *addonapiv1alpha1.ManagedClusterAddOn) (*addonapiv1alpha1.AddOnTemplate, error) {
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/addonmanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("ad
ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil())

ginkgo.By(fmt.Sprintf("Cleaning managed cluster namespace %s", clusterName))
err = t.HubKubeClient.CoreV1().Namespaces().Delete(context.TODO(), clusterName, metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// disable addon management feature gate
gomega.Eventually(func() error {
clusterManager, err := t.OperatorClient.OperatorV1().ClusterManagers().Get(context.TODO(), "cluster-manager", metav1.GetOptions{})
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/strings/slices
k8s.io/utils/trace
# open-cluster-management.io/addon-framework v0.7.1-0.20230626092851-963716af4eed
# open-cluster-management.io/addon-framework v0.7.1-0.20230705031704-6a328fa5cd63
## explicit; go 1.19
open-cluster-management.io/addon-framework/pkg/addonfactory
open-cluster-management.io/addon-framework/pkg/addonmanager
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.

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

Loading