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

Update ResourceExport's json tag as lowerCamelCase #4211

Merged
merged 1 commit into from
Sep 10, 2022
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 docs/multicluster/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ metadata:
spec:
kind: AntreaClusterNetworkPolicy
name: strict-namespace-isolation # In each importing cluster, an ACNP of name antrea-mc-strict-namespace-isolation will be created with the spec below
clusternetworkpolicy:
clusterNetworkPolicy:
priority: 1
tier: securityops
appliedTo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type EndpointsExport struct {

// ExternalEntityExport exports ExternalEntity.
type ExternalEntityExport struct {
ExternalEntitySpec v1alpha2.ExternalEntitySpec `json:"externalentityspec,omitempty"`
ExternalEntitySpec v1alpha2.ExternalEntitySpec `json:"externalEntitySpec,omitempty"`
}

// RawResourceExport exports opaque resources.
Expand All @@ -60,11 +60,11 @@ type ResourceExportSpec struct {
// If exported resource is Endpoints.
Endpoints *EndpointsExport `json:"endpoints,omitempty"`
// If exported resource is ClusterInfo.
ClusterInfo *ClusterInfo `json:"clusterinfo,omitempty"`
ClusterInfo *ClusterInfo `json:"clusterInfo,omitempty"`
// If exported resource is ExternalEntity.
ExternalEntity *ExternalEntityExport `json:"externalentity,omitempty"`
ExternalEntity *ExternalEntityExport `json:"externalEntity,omitempty"`
// If exported resource is AntreaClusterNetworkPolicy.
ClusterNetworkPolicy *v1alpha1.ClusterNetworkPolicySpec `json:"clusternetworkpolicy,omitempty"`
ClusterNetworkPolicy *v1alpha1.ClusterNetworkPolicySpec `json:"clusterNetworkPolicy,omitempty"`
// If exported resource kind is unknown.
Raw *RawResourceExport `json:"raw,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ spec:
description: ClusterID specifies the member cluster this resource
exported from.
type: string
clusterinfo:
clusterInfo:
description: If exported resource is ClusterInfo.
properties:
clusterID:
Expand All @@ -383,7 +383,7 @@ spec:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
type: object
clusternetworkpolicy:
clusterNetworkPolicy:
description: If exported resource is AntreaClusterNetworkPolicy.
properties:
appliedTo:
Expand Down Expand Up @@ -2765,10 +2765,10 @@ spec:
type: object
type: array
type: object
externalentity:
externalEntity:
description: If exported resource is ExternalEntity.
properties:
externalentityspec:
externalEntitySpec:
description: ExternalEntitySpec defines the desired state for
ExternalEntity.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
description: ClusterID specifies the member cluster this resource
exported from.
type: string
clusterinfo:
clusterInfo:
description: If exported resource is ClusterInfo.
properties:
clusterID:
Expand All @@ -78,7 +78,7 @@ spec:
description: ServiceCIDR is the IP ranges used by Service ClusterIP.
type: string
type: object
clusternetworkpolicy:
clusterNetworkPolicy:
description: If exported resource is AntreaClusterNetworkPolicy.
properties:
appliedTo:
Expand Down Expand Up @@ -2460,10 +2460,10 @@ spec:
type: object
type: array
type: object
externalentity:
externalEntity:
description: If exported resource is ExternalEntity.
properties:
externalentityspec:
externalEntitySpec:
description: ExternalEntitySpec defines the desired state for
ExternalEntity.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var (
)

func (r *ResourceImportReconciler) handleResImpUpdateForClusterNetworkPolicy(ctx context.Context, resImp *multiclusterv1alpha1.ResourceImport) (ctrl.Result, error) {
if resImp.Spec.ClusterNetworkPolicy == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions:

  1. Do we need this check for ResourceExport reconcilers too?
  2. But what will happen if this ResourceImport was not processed before mc-controller upgrade? After such change, we should either recreate all impacted resources or support old version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can skip reconciling ResourceExport if spec is empty, but the main purpose of this change is to avoid controller crash for any existing ResourceImport with empty spec. When users deploy latest manifest with this change, the existing ResourceImport spec will become empty due to mismatch json tag.
When users upgrade all member and leader clusters, they need to restart controller manually, then all impacted resources will be updated automatically because ResourceExports will be updated by member controllers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking maybe we can add an empty line in the config file so that the ConfigMap checksum annotation can be updated. In this case, user don't have to restart controller manually. Deployment will be updated and restarted automatically due to annotation change. What's your thought?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After upgrading from 1.8.0 to 1.9.0 which includes this change, mc-controller will be restarted. Why manual restart is required? But could you confirm in the current implementation, mc-controller will update all existing ResourceExports after restart? Could you verify that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, you are right. For this standalone PR, the manifest change is for CRD part only, so controller won't be restarted. But for a new release 1.9, mc-controller will be restarted.
I verified this locally, when the leader CRD is updated, the spec of existing ResourceExport will be empty, but it will be updated soon after member controller restart since there are difference between new ResourceExport and existing one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, will ResourceImport be recreated too? How about imported resources in the member cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding ResourceImport will be updated, then the member controller will be notified and handles the update event properly to refresh imported resources.

klog.V(2).InfoS("Skip reconciling ResourceImport for ClusterNetworkPolicy since it has no valid spec", "resourceimport", klog.KObj(resImp))
return ctrl.Result{}, nil
}
acnpName := types.NamespacedName{
Namespace: "",
Name: common.AntreaMCSPrefix + resImp.Spec.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var (
Namespace: leaderNamespace,
Name: "default-acnp-no-matching-tier",
}}
acnpImpNoSpecReq = ctrl.Request{NamespacedName: types.NamespacedName{
Namespace: leaderNamespace,
Name: "default-acnp-no-spec",
}}

allowAction = v1alpha1.RuleActionAllow
dropAction = v1alpha1.RuleActionDrop
Expand Down Expand Up @@ -87,6 +91,16 @@ var (
},
},
}
acnpResImportNoSpec = &mcsv1alpha1.ResourceImport{
ObjectMeta: metav1.ObjectMeta{
Namespace: leaderNamespace,
Name: "default-acnp-no-spec",
},
Spec: mcsv1alpha1.ResourceImportSpec{
Name: "default-acnp-no-spec",
Kind: common.AntreaClusterNetworkPolicyKind,
},
}
acnpResImportNoMatchingTier = &mcsv1alpha1.ResourceImport{
ObjectMeta: metav1.ObjectMeta{
Namespace: leaderNamespace,
Expand All @@ -108,7 +122,7 @@ var (

func TestResourceImportReconciler_handleCopySpanACNPCreateEvent(t *testing.T) {
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(securityOpsTier).Build()
fakeRemoteClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(acnpResImport, acnpResImportNoMatchingTier).Build()
fakeRemoteClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(acnpResImport, acnpResImportNoMatchingTier, acnpResImportNoSpec).Build()
remoteCluster := NewFakeRemoteCommonArea(fakeRemoteClient, "leader-cluster", localClusterID, "default")

tests := []struct {
Expand All @@ -129,6 +143,12 @@ func TestResourceImportReconciler_handleCopySpanACNPCreateEvent(t *testing.T) {
req: acnpImpNoMatchingTierReq,
expectedSuccess: false,
},
{
name: "import ACNP of empty spec",
acnpImportName: "acnp-no-spec",
req: acnpImpNoSpecReq,
expectedSuccess: false,
},
}
r := NewResourceImportReconciler(fakeClient, scheme, fakeClient, localClusterID, "default", remoteCluster)
for _, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
func (r *ResourceImportReconciler) handleResImpUpdateForClusterInfo(ctx context.Context, req ctrl.Request, resImp *mcsv1alpha1.ResourceImport) (ctrl.Result, error) {
klog.V(2).InfoS("Reconciling ClusterInfo of ResourceImport", "resourceimport", req.NamespacedName)
var err error
if resImp.Spec.ClusterInfo == nil {
klog.V(2).InfoS("Skip reconciling ResourceImport for ClusterInfo since it has no valid spec", "resourceimport", req.NamespacedName)
return ctrl.Result{}, nil
}
clusterInfo := *resImp.Spec.ClusterInfo

// If ClusterInfo is from local cluster, skip it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ func TestResourceImportReconciler_handleClusterInfo(t *testing.T) {
Namespace: "default",
},
}
ciResImportEmptySpec := &mcsv1alpha1.ResourceImport{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "cluster-a-default-clusterinfo-empty",
},
Spec: mcsv1alpha1.ResourceImportSpec{
Kind: common.ClusterInfoKind,
Name: "node-1",
Namespace: "default",
},
}
ciResImportLocal := &mcsv1alpha1.ResourceImport{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "cluster-d-default-clusterinfo-empty",
},
Spec: mcsv1alpha1.ResourceImportSpec{
Kind: common.ClusterInfoKind,
Name: "node-1",
Namespace: "default",
ClusterInfo: &mcsv1alpha1.ClusterInfo{
ClusterID: "cluster-d",
},
},
}
ciImportA := mcsv1alpha1.ClusterInfoImport{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Expand Down Expand Up @@ -135,6 +160,16 @@ func TestResourceImportReconciler_handleClusterInfo(t *testing.T) {
existingCIResImport: ciResImportA,
expectedCIImport: &ciImportA,
},
{
name: "skip import empty ResourceImport",
existingCIResImport: ciResImportEmptySpec,
expectedCIImport: nil,
},
{
name: "skip import ResourceImport from local",
existingCIResImport: ciResImportLocal,
expectedCIImport: nil,
},
{
name: "update ClusterInfoImport successfully",
existingCIResImport: ciResImportB,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (r *LeaderClusterSetReconciler) updateStatus() {
status := multiclusterv1alpha1.ClusterSetStatus{}
status.ObservedGeneration = r.clusterSetConfig.Generation
clusterStatuses := r.StatusManager.GetMemberClusterStatuses()
klog.InfoS("size of cluster", "size", len(clusterStatuses))
status.ClusterStatuses = clusterStatuses
sizeOfMembers := len(clusterStatuses)
status.TotalClusters = int32(sizeOfMembers)
Expand Down