Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #118 from liu-657667/feat.module_url
Browse files Browse the repository at this point in the history
Feat.module url
  • Loading branch information
gold300jin authored Sep 25, 2023
2 parents d671a08 + 1278f01 commit 56a7bf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
11 changes: 8 additions & 3 deletions module-controller/internal/controller/module_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,14 @@ func (r *ModuleReconciler) handleTerminatingModuleInstance(ctx context.Context,
}

if module.Labels[label.DeleteModuleLabel] == "" {
moduleReplicaSet := &v1alpha1.ModuleReplicaSet{}
err := r.Client.Get(ctx, types.NamespacedName{Namespace: module.Namespace, Name: module.Labels[label.ModuleReplicasetLabel]}, moduleReplicaSet)
if err != nil {
return ctrl.Result{}, err
}
// create a new module
log.Log.Info("start to create a new module", "moduleName", module.Spec.Module.Name, "module", module.Name)
err := r.createNewModule(ctx, module)
err = r.createNewModule(ctx, module, moduleReplicaSet)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -352,7 +357,7 @@ func (r *ModuleReconciler) handleAvailableModuleInstance(ctx context.Context, mo
}

// create a new module
func (r *ModuleReconciler) createNewModule(ctx context.Context, module *v1alpha1.Module) error {
func (r *ModuleReconciler) createNewModule(ctx context.Context, module *v1alpha1.Module, moduleReplicaSet *v1alpha1.ModuleReplicaSet) error {
moduleLabels := module.Labels
delete(moduleLabels, label.BaseInstanceIpLabel)
delete(moduleLabels, label.BaseInstanceNameLabel)
Expand All @@ -365,7 +370,7 @@ func (r *ModuleReconciler) createNewModule(ctx context.Context, module *v1alpha1
Namespace: module.Namespace,
},
Spec: v1alpha1.ModuleSpec{
Module: module.Spec.Module,
Module: moduleReplicaSet.Spec.Template.Spec.Module,
Selector: module.Spec.Selector,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ var _ = Describe("Module Controller", func() {
})

Context("delete module deployment with ip by deleting module", func() {

moduleReplicaSetName := "test-modulereplicaset"
updateModuleUrl := "https://module-test-url"
It("should be deleted and recreate a new one", func() {
module.Labels[label.ModuleReplicasetLabel] = "test-modulereplicaset"
module.Labels[label.ModuleReplicasetLabel] = moduleReplicaSetName
module.Labels[label.ModuleNameLabel] = "test-module"
Expect(k8sClient.Update(context.TODO(), &module)).Should(Succeed())
Expect(k8sClient.Delete(context.TODO(), &module)).Should(Succeed())
moduleReplicaSet := prepareModuleReplicaSet(namespace, moduleReplicaSetName)
moduleReplicaSet.Spec.Template.Spec.Module.Url = updateModuleUrl
Expect(k8sClient.Create(context.TODO(), &moduleReplicaSet)).Should(Succeed())
key := types.NamespacedName{
Name: moduleName,
Namespace: namespace,
Expand All @@ -95,7 +99,7 @@ var _ = Describe("Module Controller", func() {
err = k8sClient.List(context.TODO(), modules, &client.ListOptions{Namespace: module.Namespace, LabelSelector: selector})
if err == nil && len(modules.Items) > 0 {
module = modules.Items[0]
return true
return module.Spec.Module.Url == updateModuleUrl
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (r *ModuleDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func isModuleChanges(module1, module2 moduledeploymentv1alpha1.ModuleInfo) bool {
return module1.Name != module2.Name || module1.Version != module2.Version
return module1.Name != module2.Name || module1.Version != module2.Version || module1.Url != module2.Url
}

func getModuleReplicasName(moduleDeploymentName string, revision int) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (r *ModuleReplicaSetReconciler) compareAndUpdateModule(ctx context.Context,
desiredModule := moduleReplicaSet.Spec.Template.Spec.Module
for _, existedModule := range existedModuleList.Items {

needUpgradeModule := existedModule.Spec.Module.Name != desiredModule.Name || existedModule.Spec.Module.Version != desiredModule.Version || existedModule.Spec.Module.Url != desiredModule.Url
needUpgradeModule := existedModule.Spec.Module.Name != desiredModule.Name || existedModule.Spec.Module.Version != desiredModule.Version
needUninstallModule := existedModule.Spec.Module.Name != desiredModule.Name
if needUpgradeModule {
existedModule.Spec.Module.Name = desiredModule.Name
Expand Down

0 comments on commit 56a7bf3

Please sign in to comment.