Skip to content

Commit

Permalink
Fix issues imported by upgrading Openshift modules
Browse files Browse the repository at this point in the history
1. Fix 'AntreaInstall is not registered to scheme' issue. OperatorClusterClient
is used to perform CRUD operations after upgrading, and OperatorClusterClient uses
global scheme(aka `scheme.Scheme`) to register CRD. But antrea-operator creates a
new scheme by `scheme := runtime.NewScheme()`, which finally causes that CRD is not
registered to the scheme used by OperatorClusterClient. To fix this, antrea-operator
the same scheme as OperatorClusterClient.
2. Function 'apply.ApplyObject' updates its interface to receive type 'Object', so
there is no need to convert 'Object' to 'Unstructured'.
  • Loading branch information
jwsui committed Feb 23, 2023
1 parent c3abbaa commit 1e676f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
18 changes: 3 additions & 15 deletions controllers/antreainstall_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/openshift/cluster-network-operator/pkg/apply"
cnoclient "github.com/openshift/cluster-network-operator/pkg/client"
"github.com/openshift/cluster-network-operator/pkg/render"
k8sutil "github.com/openshift/cluster-network-operator/pkg/util/k8s"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -422,20 +421,9 @@ func deleteExistingPods(c client.Client, component string) error {
func updateNetworkStatus(c cnoclient.Client, clusterConfig *configv1.Network, defaultMTU int) error {
status := configutil.BuildNetworkStatus(clusterConfig, defaultMTU)
clusterConfig.Status = *status
data, err := k8sutil.ToUnstructured(clusterConfig)
if err != nil {
log.Error(err, "Failed to render configurations")
return err
}

if data != nil {
if err := apply.ApplyObject(context.TODO(), c, data, ""); err != nil {
log.Error(err, fmt.Sprintf("Could not apply (%s) %s/%s", data.GroupVersionKind(),
data.GetNamespace(), data.GetName()))
return err
}
} else {
log.Error(err, "Retrieved data for updating network status is empty.")
if err := apply.ApplyObject(context.TODO(), c, clusterConfig, ""); err != nil {
log.Error(err, fmt.Sprintf("Could not apply (%s) %s/%s", clusterConfig.GroupVersionKind(),
clusterConfig.GetNamespace(), clusterConfig.GetName()))
return err
}
log.Info("Successfully updated Network Status")
Expand Down
2 changes: 1 addition & 1 deletion controllers/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func fillAgentConfig(clusterConfig *configv1.Network, operConfig *operatorv1.Ant
if serviceCIDR, ok := antreaAgentConfig[types.ServiceCIDROption].(string); !ok {
antreaAgentConfig[types.ServiceCIDROption] = clusterConfig.Spec.ServiceNetwork[0]
} else if found := inSlice(serviceCIDR, clusterConfig.Spec.ServiceNetwork); !found {
log.Info("WARNING: option: %s is overwritten by cluster config")
log.Info("WARNING: ServiceCIDROption is overwritten by cluster config")
antreaAgentConfig[types.ServiceCIDROption] = clusterConfig.Spec.ServiceNetwork[0]
}
}
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
ocoperv1 "github.com/openshift/api/operator/v1"
cnoclient "github.com/openshift/cluster-network-operator/pkg/client"
"github.com/openshift/cluster-network-operator/pkg/names"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand All @@ -28,7 +27,7 @@ import (
)

var (
scheme = runtime.NewScheme()
scheme = clientgoscheme.Scheme
setupLog = ctrl.Log.WithName("setup")
)

Expand Down

0 comments on commit 1e676f6

Please sign in to comment.