Skip to content

Commit

Permalink
update to deployer functions for AddOnDeploymentConfig and
Browse files Browse the repository at this point in the history
ClusterManagementAddOn

In
#1470
we added support for deploying and configuring MCOA with the
capabilities field. However if we enabled a field in capabilities and
then disable it MCO would not reconcile the AddOnDeploymentConfig
correctly due to DeepDerivative, that would return true instead of
false.
  • Loading branch information
JoaoBraveCoding committed Aug 27, 2024
1 parent be95cdc commit be74f64
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 4 deletions.
4 changes: 2 additions & 2 deletions operators/pkg/deploying/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (d *Deployer) updateAddOnDeploymentConfig(
return err
}

if !apiequality.Semantic.DeepDerivative(desiredAODC.Spec, runtimeAODC.Spec) {
if !apiequality.Semantic.DeepEqual(desiredAODC.Spec, runtimeAODC.Spec) {
logUpdateInfo(runtimeObj)
if desiredAODC.ResourceVersion != runtimeAODC.ResourceVersion {
desiredAODC.ResourceVersion = runtimeAODC.ResourceVersion
Expand All @@ -395,7 +395,7 @@ func (d *Deployer) updateClusterManagementAddOn(
return err
}

if !apiequality.Semantic.DeepDerivative(desiredCMAO.Spec, runtimeCMAO.Spec) {
if !apiequality.Semantic.DeepEqual(desiredCMAO.Spec, runtimeCMAO.Spec) {
logUpdateInfo(runtimeObj)
if desiredCMAO.ResourceVersion != runtimeCMAO.ResourceVersion {
desiredCMAO.ResourceVersion = runtimeCMAO.ResourceVersion
Expand Down
138 changes: 136 additions & 2 deletions operators/pkg/deploying/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func TestDeploy(t *testing.T) {
},
},
{
name: "create and update AddOnDeploymentConfig",
name: "create and update AddOnDeploymentConfig: one variable to two",
createObj: &addonv1alpha1.AddOnDeploymentConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Expand Down Expand Up @@ -839,7 +839,63 @@ func TestDeploy(t *testing.T) {
},
},
{
name: "create and update ClusterManagementAddOn",
name: "create and update AddOnDeploymentConfig: two variables to one",
createObj: &addonv1alpha1.AddOnDeploymentConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Kind: "AddOnDeploymentConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-aodc",
Namespace: "ns1",
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
CustomizedVariables: []addonv1alpha1.CustomizedVariable{
{
Name: "test",
Value: "value",
},
{
Name: "other",
Value: "more",
},
},
},
},
updateObj: &addonv1alpha1.AddOnDeploymentConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Kind: "AddOnDeploymentConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-aodc",
Namespace: "ns1",
ResourceVersion: "1",
},
Spec: addonv1alpha1.AddOnDeploymentConfigSpec{
CustomizedVariables: []addonv1alpha1.CustomizedVariable{
{
Name: "test",
Value: "value",
},
},
},
},
validateResults: func(client client.Client) {
namespacedName := types.NamespacedName{
Name: "test-aodc",
Namespace: "ns1",
}
obj := &addonv1alpha1.AddOnDeploymentConfig{}
client.Get(context.Background(), namespacedName, obj)

if len(obj.Spec.CustomizedVariables) != 1 {
t.Fatalf("Too many Customied Variables, got %#v", obj.Spec.CustomizedVariables)
}
},
},
{
name: "create and update ClusterManagementAddOn: no placements to 2 placements",
createObj: &addonv1alpha1.ClusterManagementAddOn{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Expand Down Expand Up @@ -909,6 +965,84 @@ func TestDeploy(t *testing.T) {
}
},
},
{
name: "create and update ClusterManagementAddOn: 2 placements to 1",
createObj: &addonv1alpha1.ClusterManagementAddOn{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Kind: "ClusterManagementAddOn",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-cmao",
Namespace: "ns1",
},
Spec: addonv1alpha1.ClusterManagementAddOnSpec{
SupportedConfigs: []addonv1alpha1.ConfigMeta{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "test.io", Resource: "TestRes"},
},
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "example.io", Resource: "ExampleRes"},
},
},
InstallStrategy: addonv1alpha1.InstallStrategy{
Type: "Placements",
Placements: []addonv1alpha1.PlacementStrategy{
{
PlacementRef: addonv1alpha1.PlacementRef{Namespace: "test", Name: "test-res"},
},
{
PlacementRef: addonv1alpha1.PlacementRef{Namespace: "example", Name: "exaple-res"},
},
},
},
},
},
updateObj: &addonv1alpha1.ClusterManagementAddOn{
TypeMeta: metav1.TypeMeta{
APIVersion: "addon.open-cluster-management.io/v1alpha1",
Kind: "ClusterManagementAddOn",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-cmao",
Namespace: "ns1",
ResourceVersion: "1",
},
Spec: addonv1alpha1.ClusterManagementAddOnSpec{
SupportedConfigs: []addonv1alpha1.ConfigMeta{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "test.io", Resource: "TestRes"},
},
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "example.io", Resource: "ExampleRes"},
},
},
InstallStrategy: addonv1alpha1.InstallStrategy{
Type: "Placements",
Placements: []addonv1alpha1.PlacementStrategy{
{
PlacementRef: addonv1alpha1.PlacementRef{Namespace: "test", Name: "test-res"},
},
},
},
},
},
validateResults: func(client client.Client) {
namespacedName := types.NamespacedName{
Name: "test-cmao",
Namespace: "ns1",
}
obj := &addonv1alpha1.ClusterManagementAddOn{}
client.Get(context.Background(), namespacedName, obj)

if len(obj.Spec.SupportedConfigs) != 2 {
t.Fatalf("Missing Supported Configs, got %#v", obj.Spec.SupportedConfigs)
}
if len(obj.Spec.InstallStrategy.Placements) != 1 {
t.Fatalf("Missing Placements, got %#v", obj.Spec.InstallStrategy.Placements)
}
},
},
}

scheme := runtime.NewScheme()
Expand Down

0 comments on commit be74f64

Please sign in to comment.