diff --git a/charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml b/charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml index b015326daa3..673876d6c3d 100644 --- a/charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml +++ b/charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml @@ -47,15 +47,11 @@ spec: additionalProperties: type: string type: object - natType: - type: string nodeName: description: NodeName is the Node hosting this endpoint. type: string publicIP: type: string - publicPort: - type: integer underNAT: type: boolean required: @@ -108,15 +104,11 @@ spec: additionalProperties: type: string type: object - natType: - type: string nodeName: description: NodeName is the Node hosting this endpoint. type: string publicIP: type: string - publicPort: - type: integer underNAT: type: boolean required: diff --git a/cmd/yurt-manager/app/options/generic.go b/cmd/yurt-manager/app/options/generic.go index c3099d95321..cdcec31768e 100644 --- a/cmd/yurt-manager/app/options/generic.go +++ b/cmd/yurt-manager/app/options/generic.go @@ -47,8 +47,8 @@ func NewGenericOptions() *GenericOptions { ResourceName: "yurt-manager", ResourceNamespace: "kube-system", }, - RestConfigQPS: 30, - RestConfigBurst: 50, + RestConfigQPS: 50, + RestConfigBurst: 100, WorkingNamespace: "kube-system", DisabledWebhooks: []string{}, }, diff --git a/hack/lib/common.sh b/hack/lib/common.sh index fc50ab105f6..210c27ec183 100644 --- a/hack/lib/common.sh +++ b/hack/lib/common.sh @@ -69,6 +69,7 @@ project_info() { versionSeparator="," echo "-X ${PROJECT_INFO_PKG}.separator=${versionSeparator}" echo "-X ${PROJECT_INFO_PKG}.maintainingVersions=${maintainingVersions}" + echo "-X ${PROJECT_INFO_PKG}.nodePoolLabelKey=${NODEPOOL_LABEL_KEY}" } # get_binary_dir_with_arch generated the binary's directory with GOOS and GOARCH. diff --git a/hack/lib/init.sh b/hack/lib/init.sh index bb15af2a65b..822594892bf 100644 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -28,5 +28,6 @@ LABEL_PREFIX=${LABEL_PREFIX:-openyurt.io} GIT_VERSION=${GIT_VERSION:-$(git describe --abbrev=0 --tags)} GIT_COMMIT=$(git rev-parse HEAD) BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') +NODEPOOL_LABEL_KEY=${NODEPOOL_LABEL_KEY:-apps.openyurt.io/nodepool} source "${YURT_ROOT}/hack/lib/common.sh" \ No newline at end of file diff --git a/pkg/apis/apps/well_known_labels_annotations.go b/pkg/apis/apps/well_known_labels_annotations.go index ecf4abde208..2fe3e5d4059 100644 --- a/pkg/apis/apps/well_known_labels_annotations.go +++ b/pkg/apis/apps/well_known_labels_annotations.go @@ -37,9 +37,7 @@ const ( // NodePool related labels and annotations const ( AnnotationPrevAttrs = "nodepool.openyurt.io/previous-attributes" - NodePoolLabel = "apps.openyurt.io/nodepool" DesiredNodePoolLabel = "apps.openyurt.io/desired-nodepool" - NodePoolTypeLabel = "nodepool.openyurt.io/type" NodePoolHostNetworkLabel = "nodepool.openyurt.io/hostnetwork" NodePoolChangedEvent = "NodePoolChanged" ) diff --git a/pkg/apis/raven/v1alpha1/gateway_conversion.go b/pkg/apis/raven/v1alpha1/gateway_conversion.go index 6b6e04118a8..6192bfc4a21 100644 --- a/pkg/apis/raven/v1alpha1/gateway_conversion.go +++ b/pkg/apis/raven/v1alpha1/gateway_conversion.go @@ -49,14 +49,12 @@ func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.ProxyConfig.Replicas = 1 for _, eps := range src.Spec.Endpoints { dst.Spec.Endpoints = append(dst.Spec.Endpoints, v1beta1.Endpoint{ - NodeName: eps.NodeName, - PublicIP: eps.PublicIP, - UnderNAT: eps.UnderNAT, - PublicPort: eps.PublicPort, - NATType: eps.NATType, - Config: eps.Config, - Type: v1beta1.Tunnel, - Port: v1beta1.DefaultTunnelServerExposedPort, + NodeName: eps.NodeName, + PublicIP: eps.PublicIP, + UnderNAT: eps.UnderNAT, + Config: eps.Config, + Type: v1beta1.Tunnel, + Port: v1beta1.DefaultTunnelServerExposedPort, }) } for _, node := range src.Status.Nodes { @@ -69,14 +67,12 @@ func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error { if src.Status.ActiveEndpoint != nil { dst.Status.ActiveEndpoints = []*v1beta1.Endpoint{ { - NodeName: src.Status.ActiveEndpoint.NodeName, - PublicIP: src.Status.ActiveEndpoint.PublicIP, - UnderNAT: src.Status.ActiveEndpoint.UnderNAT, - PublicPort: src.Status.ActiveEndpoint.PublicPort, - NATType: src.Status.ActiveEndpoint.NATType, - Config: src.Status.ActiveEndpoint.Config, - Type: v1beta1.Tunnel, - Port: v1beta1.DefaultTunnelServerExposedPort, + NodeName: src.Status.ActiveEndpoint.NodeName, + PublicIP: src.Status.ActiveEndpoint.PublicIP, + UnderNAT: src.Status.ActiveEndpoint.UnderNAT, + Config: src.Status.ActiveEndpoint.Config, + Type: v1beta1.Tunnel, + Port: v1beta1.DefaultTunnelServerExposedPort, }, } } @@ -95,12 +91,10 @@ func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error { dst.Spec.ExposeType = ExposeType(src.Spec.ExposeType) for _, eps := range src.Spec.Endpoints { dst.Spec.Endpoints = append(dst.Spec.Endpoints, Endpoint{ - NodeName: eps.NodeName, - PublicIP: eps.PublicIP, - UnderNAT: eps.UnderNAT, - PublicPort: eps.PublicPort, - NATType: eps.NATType, - Config: eps.Config, + NodeName: eps.NodeName, + PublicIP: eps.PublicIP, + UnderNAT: eps.UnderNAT, + Config: eps.Config, }) } for _, node := range src.Status.Nodes { @@ -118,12 +112,10 @@ func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error { dst.Status.ActiveEndpoint = nil } else { dst.Status.ActiveEndpoint = &Endpoint{ - NodeName: src.Status.ActiveEndpoints[0].NodeName, - PublicIP: src.Status.ActiveEndpoints[0].PublicIP, - UnderNAT: src.Status.ActiveEndpoints[0].UnderNAT, - PublicPort: src.Status.ActiveEndpoints[0].PublicPort, - NATType: src.Status.ActiveEndpoints[0].NATType, - Config: src.Status.ActiveEndpoints[0].Config, + NodeName: src.Status.ActiveEndpoints[0].NodeName, + PublicIP: src.Status.ActiveEndpoints[0].PublicIP, + UnderNAT: src.Status.ActiveEndpoints[0].UnderNAT, + Config: src.Status.ActiveEndpoints[0].Config, } } klog.Infof("convert from v1beta1 to v1alpha1 for %s", dst.Name) diff --git a/pkg/apis/raven/v1alpha1/gateway_types.go b/pkg/apis/raven/v1alpha1/gateway_types.go index b5fa5539145..551254e8bb0 100644 --- a/pkg/apis/raven/v1alpha1/gateway_types.go +++ b/pkg/apis/raven/v1alpha1/gateway_types.go @@ -59,12 +59,10 @@ type GatewaySpec struct { // TODO add priority field? type Endpoint struct { // NodeName is the Node hosting this endpoint. - NodeName string `json:"nodeName"` - UnderNAT bool `json:"underNAT,omitempty"` - NATType string `json:"natType,omitempty"` - PublicIP string `json:"publicIP,omitempty"` - PublicPort int `json:"publicPort,omitempty"` - Config map[string]string `json:"config,omitempty"` + NodeName string `json:"nodeName"` + UnderNAT bool `json:"underNAT,omitempty"` + PublicIP string `json:"publicIP,omitempty"` + Config map[string]string `json:"config,omitempty"` } // NodeInfo stores information of node managed by Gateway. diff --git a/pkg/projectinfo/projectinfo.go b/pkg/projectinfo/projectinfo.go index 63893289165..fa83f5d4127 100644 --- a/pkg/projectinfo/projectinfo.go +++ b/pkg/projectinfo/projectinfo.go @@ -30,6 +30,7 @@ var ( buildDate = "1970-01-01T00:00:00Z" maintainingVersions = "unknown" separator = "," + nodePoolLabelKey = "apps.openyurt.io/nodepool" ) func ShortAgentVersion() string { @@ -90,21 +91,11 @@ func GetTunnelName() string { return projectPrefix + "tunnel" } -// GetYurtControllerManagerName returns name of openyurt controller-manager: yurtcontroller-manager -func GetYurtControllerManagerName() string { - return projectPrefix + "controller-manager" -} - // GetYurtManagerName returns name of openyurt-manager: yurt-manager func GetYurtManagerName() string { return "yurt-manager" } -// GetYurtAppManagerName returns name of tunnel: yurtapp-manager -func GetYurtAppManagerName() string { - return projectPrefix + "app-manager" -} - // GetAutonomyAnnotation returns annotation key for node autonomy func GetAutonomyAnnotation() string { return fmt.Sprintf("node.beta.%s/autonomy", labelPrefix) @@ -119,26 +110,33 @@ func normalizeGitCommit(commit string) string { return commit } +// GetNodePoolLabel returns label for specifying nodepool +func GetNodePoolLabel() string { + return nodePoolLabelKey +} + // Info contains version information. type Info struct { - GitVersion string `json:"gitVersion"` - GitCommit string `json:"gitCommit"` - BuildDate string `json:"buildDate"` - GoVersion string `json:"goVersion"` - Compiler string `json:"compiler"` - Platform string `json:"platform"` - AllVersions []string `json:"allVersions"` + GitVersion string `json:"gitVersion"` + GitCommit string `json:"gitCommit"` + BuildDate string `json:"buildDate"` + GoVersion string `json:"goVersion"` + Compiler string `json:"compiler"` + Platform string `json:"platform"` + AllVersions []string `json:"allVersions"` + NodePoolLabelKey string `json:"nodePoolLabelKey"` } // Get returns the overall codebase version. func Get() Info { return Info{ - GitVersion: gitVersion, - GitCommit: normalizeGitCommit(gitCommit), - BuildDate: buildDate, - GoVersion: runtime.Version(), - Compiler: runtime.Compiler, - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), - AllVersions: strings.Split(maintainingVersions, separator), + GitVersion: gitVersion, + GitCommit: normalizeGitCommit(gitCommit), + BuildDate: buildDate, + GoVersion: runtime.Version(), + Compiler: runtime.Compiler, + Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + AllVersions: strings.Split(maintainingVersions, separator), + NodePoolLabelKey: nodePoolLabelKey, } } diff --git a/pkg/util/certmanager/pki.go b/pkg/util/certmanager/pki.go index 087e4d4adc4..bce98c5a2e1 100644 --- a/pkg/util/certmanager/pki.go +++ b/pkg/util/certmanager/pki.go @@ -185,3 +185,10 @@ func GenCertPoolUseCA(caFile string) (*x509.CertPool, error) { certPool.AppendCertsFromPEM(caData) return certPool, nil } + +// GenCertPoolUseCAData generates a x509 CertPool based on the given CA data +func GenCertPoolUseCAData(caData []byte) (*x509.CertPool, error) { + certPool := x509.NewCertPool() + certPool.AppendCertsFromPEM(caData) + return certPool, nil +} diff --git a/pkg/yurtadm/cmd/join/join.go b/pkg/yurtadm/cmd/join/join.go index 45bfaf61660..bc388dd84aa 100644 --- a/pkg/yurtadm/cmd/join/join.go +++ b/pkg/yurtadm/cmd/join/join.go @@ -30,7 +30,7 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "k8s.io/klog/v2" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" kubeconfigutil "github.com/openyurtio/openyurt/pkg/util/kubeconfig" "github.com/openyurtio/openyurt/pkg/util/kubernetes/kubeadm/app/util/apiclient" "github.com/openyurtio/openyurt/pkg/yurtadm/cmd/join/joindata" @@ -355,7 +355,7 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) { return nil, errors.Errorf("when --nodepool-name is specified, the specified nodePool should be exist.") } // add nodePool label for node by kubelet - data.nodeLabels[apps.NodePoolLabel] = opt.nodePoolName + data.nodeLabels[projectinfo.GetNodePoolLabel()] = opt.nodePoolName } // check static pods has value and yurtstaticset is already exist diff --git a/pkg/yurthub/certificate/interfaces.go b/pkg/yurthub/certificate/interfaces.go index 0a8c74d7b03..4d0d9a94b88 100644 --- a/pkg/yurthub/certificate/interfaces.go +++ b/pkg/yurthub/certificate/interfaces.go @@ -45,6 +45,7 @@ type YurtClientCertificateManager interface { Stop() UpdateBootstrapConf(joinToken string) error GetHubConfFile() string + GetCAData() []byte GetCaFile() string GetAPIServerClientCert() *tls.Certificate } diff --git a/pkg/yurthub/certificate/kubeletcertificate/kubelet_certificate.go b/pkg/yurthub/certificate/kubeletcertificate/kubelet_certificate.go index 0db01ee19b4..c827437f1d2 100644 --- a/pkg/yurthub/certificate/kubeletcertificate/kubelet_certificate.go +++ b/pkg/yurthub/certificate/kubeletcertificate/kubelet_certificate.go @@ -21,6 +21,7 @@ import ( "crypto/x509" "errors" "fmt" + "os" "time" "k8s.io/klog/v2" @@ -40,6 +41,7 @@ type kubeletCertManager struct { kubeletCAFile string kubeletPemFile string cert *tls.Certificate + caData []byte } func NewKubeletCertManager(kubeConfFile, kubeletCAFile, kubeletPemFile string) (certificate.YurtClientCertificateManager, error) { @@ -50,6 +52,10 @@ func NewKubeletCertManager(kubeConfFile, kubeletCAFile, kubeletPemFile string) ( if exist, _ := util.FileExists(kubeletCAFile); !exist { return nil, KubeletCANotExistErr } + caData, err := os.ReadFile(kubeletCAFile) + if err != nil { + return nil, err + } if exist, _ := util.FileExists(kubeletPemFile); !exist { return nil, KubeletPemNotExistErr @@ -65,6 +71,7 @@ func NewKubeletCertManager(kubeConfFile, kubeletCAFile, kubeletPemFile string) ( kubeletCAFile: kubeletCAFile, kubeletPemFile: kubeletPemFile, cert: cert, + caData: caData, }, nil } @@ -84,6 +91,10 @@ func (kcm *kubeletCertManager) GetHubConfFile() string { return kcm.kubeConfFile } +func (kcm *kubeletCertManager) GetCAData() []byte { + return kcm.caData +} + func (kcm *kubeletCertManager) GetCaFile() string { return kcm.kubeletCAFile } diff --git a/pkg/yurthub/certificate/manager/manager.go b/pkg/yurthub/certificate/manager/manager.go index c06b7dec172..a17f7f34aaf 100644 --- a/pkg/yurthub/certificate/manager/manager.go +++ b/pkg/yurthub/certificate/manager/manager.go @@ -32,7 +32,6 @@ import ( "github.com/openyurtio/openyurt/pkg/yurthub/certificate/kubeletcertificate" hubServerCert "github.com/openyurtio/openyurt/pkg/yurthub/certificate/server" "github.com/openyurtio/openyurt/pkg/yurthub/certificate/token" - "github.com/openyurtio/openyurt/pkg/yurthub/util" ) const ( @@ -123,12 +122,8 @@ func (hcm *yurtHubCertManager) Ready() bool { errs = append(errs, apiServerClientCertNotReadyError) } - if exist, err := util.FileExists(hcm.YurtClientCertificateManager.GetCaFile()); !exist { - if err == nil { - errs = append(errs, caCertIsNotReadyError) - } else { - errs = append(errs, err) - } + if len(hcm.YurtClientCertificateManager.GetCAData()) == 0 { + errs = append(errs, caCertIsNotReadyError) } if hcm.GetHubServerCert() == nil { diff --git a/pkg/yurthub/certificate/manager/manager_test.go b/pkg/yurthub/certificate/manager/manager_test.go index fda1226619c..385a0fbcb30 100644 --- a/pkg/yurthub/certificate/manager/manager_test.go +++ b/pkg/yurthub/certificate/manager/manager_test.go @@ -24,16 +24,11 @@ import ( "testing" "time" - "github.com/pkg/errors" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/tools/clientcmd" - certutil "k8s.io/client-go/util/cert" "github.com/openyurtio/openyurt/cmd/yurthub/app/options" "github.com/openyurtio/openyurt/pkg/projectinfo" - kubeconfigutil "github.com/openyurtio/openyurt/pkg/util/kubeconfig" "github.com/openyurtio/openyurt/pkg/yurthub/certificate/testdata" - "github.com/openyurtio/openyurt/pkg/yurthub/util" ) func TestGetHubServerCertFile(t *testing.T) { @@ -108,33 +103,6 @@ func TestReady(t *testing.T) { if mgr.Ready() { return true, nil } - - if exist, err := util.FileExists(mgr.GetCaFile()); !exist { - if err != nil { - t.Logf("could not get ca file(%s), %v", mgr.GetCaFile(), err) - return false, err - } - - if exist, err := util.FileExists(mgr.GetHubConfFile()); err != nil { - t.Logf("could not get hub conf file(%s), %v", mgr.GetHubConfFile(), err) - return false, nil - } else if exist { - t.Logf("%s file already exists, so use it to create ca file", mgr.GetHubConfFile()) - hubKubeConfig, err := clientcmd.LoadFromFile(mgr.GetHubConfFile()) - if err != nil { - return false, err - } - - cluster := kubeconfigutil.GetClusterFromKubeConfig(hubKubeConfig) - if cluster != nil { - if err := certutil.WriteCert(mgr.GetCaFile(), cluster.CertificateAuthorityData); err != nil { - return false, errors.Wrap(err, "couldn't save the CA certificate to disk") - } - } else { - return false, errors.Errorf("couldn't prepare ca.crt(%s) file", mgr.GetCaFile()) - } - } - } return false, nil }) @@ -161,8 +129,14 @@ func TestReady(t *testing.T) { return } newMgr.Start() - if !newMgr.Ready() { - t.Errorf("certificates can not be reused") + err = wait.PollImmediate(2*time.Second, 1*time.Minute, func() (done bool, err error) { + if mgr.Ready() { + return true, nil + } + return false, nil + }) + if err != nil { + t.Errorf("certificates are not reused, %v", err) } newMgr.Stop() diff --git a/pkg/yurthub/certificate/token/token.go b/pkg/yurthub/certificate/token/token.go index 8a9f49bba4a..b332a23de7b 100644 --- a/pkg/yurthub/certificate/token/token.go +++ b/pkg/yurthub/certificate/token/token.go @@ -80,6 +80,7 @@ type yurtHubClientCertManager struct { joinToken string bootstrapFile string dialer *util.Dialer + caData []byte } // NewYurtHubClientCertManager new a YurtCertificateManager instance @@ -203,11 +204,17 @@ func (ycm *yurtHubClientCertManager) prepareConfigAndCaFile() error { if err := certutil.WriteCert(ycm.GetCaFile(), cluster.CertificateAuthorityData); err != nil { return errors.Wrap(err, "couldn't save the CA certificate to disk") } + ycm.caData = cluster.CertificateAuthorityData } else { return errors.Errorf("couldn't prepare ca.crt(%s) file", ycm.GetCaFile()) } } else { klog.V(2).Infof("%s file already exists, so reuse it", ycm.GetCaFile()) + caData, err := os.ReadFile(ycm.GetCaFile()) + if err != nil { + return err + } + ycm.caData = caData } return nil } @@ -250,11 +257,17 @@ func (ycm *yurtHubClientCertManager) prepareConfigAndCaFile() error { if err := certutil.WriteCert(ycm.GetCaFile(), cluster.CertificateAuthorityData); err != nil { return errors.Wrap(err, "couldn't save the CA certificate to disk") } + ycm.caData = cluster.CertificateAuthorityData } else { return errors.Errorf("couldn't prepare ca.crt(%s) file", ycm.GetCaFile()) } } else { klog.V(2).Infof("%s file already exists, so reuse it", ycm.GetCaFile()) + caData, err := os.ReadFile(ycm.GetCaFile()) + if err != nil { + return err + } + ycm.caData = caData } return nil @@ -284,6 +297,10 @@ func (ycm *yurtHubClientCertManager) getBootstrapConfFile() string { return filepath.Join(ycm.hubRunDir, bootstrapConfigFileName) } +func (ycm *yurtHubClientCertManager) GetCAData() []byte { + return ycm.caData +} + // GetCaFile returns the path of ca file func (ycm *yurtHubClientCertManager) GetCaFile() string { return filepath.Join(ycm.getPkiDir(), hubCaFileName) diff --git a/pkg/yurthub/filter/hostnetworkpropagation/filter.go b/pkg/yurthub/filter/hostnetworkpropagation/filter.go index dc0c5baef3e..e6baf217f29 100644 --- a/pkg/yurthub/filter/hostnetworkpropagation/filter.go +++ b/pkg/yurthub/filter/hostnetworkpropagation/filter.go @@ -29,8 +29,8 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" - "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -91,7 +91,7 @@ func (hpf *hostNetworkPropagationFilter) resolveNodePoolName(pod *corev1.Pod) st klog.Warningf("could not get node(%s) in hostNetworkPropagationFilter, %v", pod.Spec.NodeName, err) return hpf.nodePoolName } - hpf.nodePoolName = node.Labels[apps.NodePoolLabel] + hpf.nodePoolName = node.Labels[projectinfo.GetNodePoolLabel()] return hpf.nodePoolName } diff --git a/pkg/yurthub/filter/hostnetworkpropagation/filter_test.go b/pkg/yurthub/filter/hostnetworkpropagation/filter_test.go index 8be6a6a54b6..7e363cb4c68 100644 --- a/pkg/yurthub/filter/hostnetworkpropagation/filter_test.go +++ b/pkg/yurthub/filter/hostnetworkpropagation/filter_test.go @@ -31,8 +31,8 @@ import ( k8sfake "k8s.io/client-go/kubernetes/fake" "github.com/openyurtio/openyurt/pkg/apis" - "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/util" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -200,7 +200,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "pool-foo", + projectinfo.GetNodePoolLabel(): "pool-foo", }, }, }, @@ -242,7 +242,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "pool-foo", + projectinfo.GetNodePoolLabel(): "pool-foo", }, }, }, @@ -286,7 +286,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "pool-foo", + projectinfo.GetNodePoolLabel(): "pool-foo", }, }, }, @@ -329,7 +329,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "unknown-pool", + projectinfo.GetNodePoolLabel(): "unknown-pool", }, }, }, @@ -380,7 +380,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "pool-foo", + projectinfo.GetNodePoolLabel(): "pool-foo", }, }, }, @@ -441,7 +441,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node-foo", Labels: map[string]string{ - apps.NodePoolLabel: "pool-foo", + projectinfo.GetNodePoolLabel(): "pool-foo", }, }, }, diff --git a/pkg/yurthub/filter/nodeportisolation/filter.go b/pkg/yurthub/filter/nodeportisolation/filter.go index 9b443125562..7d7f85ea7a7 100644 --- a/pkg/yurthub/filter/nodeportisolation/filter.go +++ b/pkg/yurthub/filter/nodeportisolation/filter.go @@ -28,7 +28,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/klog/v2" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -130,7 +130,7 @@ func (nif *nodePortIsolationFilter) resolveNodePoolName() string { klog.Warningf("skip isolateNodePortService filter, could not get node(%s), %v", nif.nodeName, err) return nif.nodePoolName } - nif.nodePoolName = node.Labels[apps.NodePoolLabel] + nif.nodePoolName = node.Labels[projectinfo.GetNodePoolLabel()] return nif.nodePoolName } diff --git a/pkg/yurthub/filter/nodeportisolation/filter_test.go b/pkg/yurthub/filter/nodeportisolation/filter_test.go index c00279050b9..e44e47e2c37 100644 --- a/pkg/yurthub/filter/nodeportisolation/filter_test.go +++ b/pkg/yurthub/filter/nodeportisolation/filter_test.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/kubernetes/fake" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/util" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -92,7 +92,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo", Annotations: map[string]string{ - apps.NodePoolLabel: nodePoolName, + projectinfo.GetNodePoolLabel(): nodePoolName, }, }, } diff --git a/pkg/yurthub/filter/servicetopology/filter.go b/pkg/yurthub/filter/servicetopology/filter.go index 31bbf72cdc5..9f1c3c1c437 100644 --- a/pkg/yurthub/filter/servicetopology/filter.go +++ b/pkg/yurthub/filter/servicetopology/filter.go @@ -33,8 +33,8 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" - "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -122,7 +122,7 @@ func (stf *serviceTopologyFilter) resolveNodePoolName() string { klog.Warningf("could not get node(%s) in serviceTopologyFilter filter, %v", stf.nodeName, err) return stf.nodePoolName } - stf.nodePoolName = node.Labels[apps.NodePoolLabel] + stf.nodePoolName = node.Labels[projectinfo.GetNodePoolLabel()] return stf.nodePoolName } diff --git a/pkg/yurthub/filter/servicetopology/filter_test.go b/pkg/yurthub/filter/servicetopology/filter_test.go index 01538a86b22..4ec0801c507 100644 --- a/pkg/yurthub/filter/servicetopology/filter_test.go +++ b/pkg/yurthub/filter/servicetopology/filter_test.go @@ -34,8 +34,8 @@ import ( k8sfake "k8s.io/client-go/kubernetes/fake" "github.com/openyurtio/openyurt/pkg/apis" - "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/util" "github.com/openyurtio/openyurt/pkg/yurthub/filter" ) @@ -137,7 +137,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -145,7 +145,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -153,7 +153,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -282,7 +282,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -290,7 +290,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -298,7 +298,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -434,7 +434,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -442,7 +442,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -450,7 +450,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -586,7 +586,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -594,7 +594,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -602,7 +602,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -750,7 +750,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -758,7 +758,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -885,7 +885,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -893,7 +893,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -901,7 +901,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1011,7 +1011,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1019,7 +1019,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1027,7 +1027,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1134,7 +1134,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1142,7 +1142,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1150,7 +1150,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1283,7 +1283,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1291,7 +1291,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1299,7 +1299,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1415,7 +1415,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1423,7 +1423,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1431,7 +1431,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1553,7 +1553,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1561,7 +1561,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1569,7 +1569,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1691,7 +1691,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1699,7 +1699,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1707,7 +1707,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1839,7 +1839,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1847,7 +1847,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1950,7 +1950,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -1958,7 +1958,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -1966,7 +1966,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2056,7 +2056,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2064,7 +2064,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2072,7 +2072,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2171,7 +2171,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2179,7 +2179,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2187,7 +2187,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2301,7 +2301,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2309,7 +2309,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2317,7 +2317,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2435,7 +2435,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2443,7 +2443,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2451,7 +2451,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2569,7 +2569,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2577,7 +2577,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2585,7 +2585,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2711,7 +2711,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2719,7 +2719,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2824,7 +2824,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2832,7 +2832,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2840,7 +2840,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2932,7 +2932,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -2940,7 +2940,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -2948,7 +2948,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -3040,7 +3040,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -3048,7 +3048,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -3056,7 +3056,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -3140,7 +3140,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: currentNodeName, Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -3148,7 +3148,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -3156,7 +3156,7 @@ func TestFilter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, diff --git a/pkg/yurthub/transport/transport.go b/pkg/yurthub/transport/transport.go index 378e19a4dd4..b112dbc7c95 100644 --- a/pkg/yurthub/transport/transport.go +++ b/pkg/yurthub/transport/transport.go @@ -34,8 +34,8 @@ type CertGetter interface { // GetAPIServerClientCert returns the currently selected certificate, as well as // the associated certificate and key data in PEM format. GetAPIServerClientCert() *tls.Certificate - // Return CA file path. - GetCaFile() string + // GetCAData returns CA file data. + GetCAData() []byte } // Interface is an transport interface for managing clients that used to connecting kube-apiserver @@ -60,13 +60,12 @@ type transportManager struct { // NewTransportManager create a transport interface object. func NewTransportManager(certGetter CertGetter, stopCh <-chan struct{}) (Interface, error) { - caFile := certGetter.GetCaFile() - if len(caFile) == 0 { - return nil, fmt.Errorf("ca cert file was not prepared when new transport") + caData := certGetter.GetCAData() + if len(caData) == 0 { + return nil, fmt.Errorf("ca cert data was not prepared when new transport") } - klog.V(2).Infof("use %s ca cert file to access remote server", caFile) - cfg, err := tlsConfig(certGetter.GetAPIServerClientCert, caFile) + cfg, err := tlsConfig(certGetter.GetAPIServerClientCert, caData) if err != nil { klog.Errorf("could not get tls config when new transport, %v", err) return nil, err @@ -81,7 +80,7 @@ func NewTransportManager(certGetter CertGetter, stopCh <-chan struct{}) (Interfa DialContext: d.DialContext, }) - bearerTLSCfg, err := tlsConfig(nil, caFile) + bearerTLSCfg, err := tlsConfig(nil, caData) if err != nil { klog.Errorf("could not get tls config when new bearer transport, %v", err) return nil, err @@ -151,9 +150,9 @@ func (tm *transportManager) start() { }, 10*time.Second, tm.stopCh) } -func tlsConfig(current func() *tls.Certificate, caFile string) (*tls.Config, error) { +func tlsConfig(current func() *tls.Certificate, caData []byte) (*tls.Config, error) { // generate the TLS configuration based on the latest certificate - rootCert, err := certmanager.GenCertPoolUseCA(caFile) + rootCert, err := certmanager.GenCertPoolUseCAData(caData) if err != nil { klog.Errorf("could not generate a x509 CertPool based on the given CA file, %v", err) return nil, err diff --git a/pkg/yurthub/yurtcoordinator/certmanager/certmanager.go b/pkg/yurthub/yurtcoordinator/certmanager/certmanager.go index 6e914ef80d2..0facbbf407b 100644 --- a/pkg/yurthub/yurtcoordinator/certmanager/certmanager.go +++ b/pkg/yurthub/yurtcoordinator/certmanager/certmanager.go @@ -98,6 +98,7 @@ type CertManager struct { coordinatorCert *tls.Certificate nodeLeaseProxyCert *tls.Certificate store fs.FileSystemOperator + caData []byte // Used for unit test. secret *corev1.Secret @@ -115,6 +116,10 @@ func (c *CertManager) GetNodeLeaseProxyClientCert() *tls.Certificate { return c.nodeLeaseProxyCert } +func (c *CertManager) GetCAData() []byte { + return c.caData +} + func (c *CertManager) GetCaFile() string { return c.GetFilePath(RootCA) } @@ -162,6 +167,7 @@ func (c *CertManager) updateCerts(secret *corev1.Secret) { if err := c.createOrUpdateFile(c.GetFilePath(RootCA), ca); err != nil { klog.Errorf("could not update ca, %v", err) } + c.caData = ca } if cook { diff --git a/pkg/yurthub/yurtcoordinator/coordinator.go b/pkg/yurthub/yurtcoordinator/coordinator.go index 591660d1225..730a59dd5b4 100644 --- a/pkg/yurthub/yurtcoordinator/coordinator.go +++ b/pkg/yurthub/yurtcoordinator/coordinator.go @@ -105,8 +105,8 @@ type coordinator struct { statusInfoChan chan statusInfo isPoolCacheSynced bool certMgr *certmanager.CertManager - // cloudCAFilePath is the file path of cloud kubernetes cluster CA cert. - cloudCAFilePath string + // cloudCAFileData is the file data of cloud kubernetes cluster CA cert. + cloudCAFileData []byte // cloudHealthChecker is health checker of cloud APIServers. It is used to // pick a healthy cloud APIServer to proxy heartbeats. cloudHealthChecker healthchecker.MultipleBackendsHealthChecker @@ -153,7 +153,7 @@ func NewCoordinator( coordinator := &coordinator{ ctx: ctx, - cloudCAFilePath: cfg.CertManager.GetCaFile(), + cloudCAFileData: cfg.CertManager.GetCAData(), cloudHealthChecker: cloudHealthChecker, etcdStorageCfg: etcdStorageCfg, restConfigMgr: restMgr, @@ -425,7 +425,7 @@ func (coordinator *coordinator) newNodeLeaseProxyClient() (coordclientset.LeaseI restCfg := &rest.Config{ Host: healthyCloudServer.String(), TLSClientConfig: rest.TLSClientConfig{ - CAFile: coordinator.cloudCAFilePath, + CAData: coordinator.cloudCAFileData, CertFile: coordinator.certMgr.GetFilePath(certmanager.NodeLeaseProxyClientCert), KeyFile: coordinator.certMgr.GetFilePath(certmanager.NodeLeaseProxyClientKey), }, diff --git a/pkg/yurtmanager/controller/controller.go b/pkg/yurtmanager/controller/controller.go index f5ed8250b58..dff330ce2be 100644 --- a/pkg/yurtmanager/controller/controller.go +++ b/pkg/yurtmanager/controller/controller.go @@ -115,6 +115,8 @@ func SetupWithManager(ctx context.Context, c *config.CompletedConfig, m manager. continue } return err + } else { + klog.Infof("controller %s is added", controllerName) } } diff --git a/pkg/yurtmanager/controller/nodepool/nodepool_controller.go b/pkg/yurtmanager/controller/nodepool/nodepool_controller.go index 9ea4b1565a9..bf6fa51f550 100644 --- a/pkg/yurtmanager/controller/nodepool/nodepool_controller.go +++ b/pkg/yurtmanager/controller/nodepool/nodepool_controller.go @@ -34,8 +34,8 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config" "github.com/openyurtio/openyurt/cmd/yurt-manager/names" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" poolconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodepool/config" ) @@ -138,7 +138,7 @@ func (r *ReconcileNodePool) Reconcile(ctx context.Context, req reconcile.Request var currentNodeList corev1.NodeList if err := r.List(ctx, ¤tNodeList, client.MatchingLabels(map[string]string{ - apps.NodePoolLabel: nodePool.GetName(), + projectinfo.GetNodePoolLabel(): nodePool.GetName(), })); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } diff --git a/pkg/yurtmanager/controller/nodepool/nodepool_controller_test.go b/pkg/yurtmanager/controller/nodepool/nodepool_controller_test.go index dfff1242bee..41b0536708c 100644 --- a/pkg/yurtmanager/controller/nodepool/nodepool_controller_test.go +++ b/pkg/yurtmanager/controller/nodepool/nodepool_controller_test.go @@ -31,8 +31,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/openyurtio/openyurt/pkg/apis" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" poolconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodepool/config" ) @@ -42,7 +42,7 @@ func prepareNodes() []client.Object { ObjectMeta: metav1.ObjectMeta{ Name: "node1", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, Status: corev1.NodeStatus{ @@ -58,7 +58,7 @@ func prepareNodes() []client.Object { ObjectMeta: metav1.ObjectMeta{ Name: "node2", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, Status: corev1.NodeStatus{ @@ -74,7 +74,7 @@ func prepareNodes() []client.Object { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "beijing", + projectinfo.GetNodePoolLabel(): "beijing", }, }, }, @@ -82,7 +82,7 @@ func prepareNodes() []client.Object { ObjectMeta: metav1.ObjectMeta{ Name: "node4", Labels: map[string]string{ - apps.NodePoolLabel: "beijing", + projectinfo.GetNodePoolLabel(): "beijing", }, }, Status: corev1.NodeStatus{ @@ -197,8 +197,8 @@ func TestReconcile(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node3", Labels: map[string]string{ - apps.NodePoolLabel: "beijing", - "region": "beijing", + projectinfo.GetNodePoolLabel(): "beijing", + "region": "beijing", }, Annotations: map[string]string{ "nodepool.openyurt.io/previous-attributes": "{\"labels\":{\"region\":\"beijing\"}}", @@ -209,8 +209,8 @@ func TestReconcile(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "node4", Labels: map[string]string{ - apps.NodePoolLabel: "beijing", - "region": "beijing", + projectinfo.GetNodePoolLabel(): "beijing", + "region": "beijing", }, Annotations: map[string]string{ "nodepool.openyurt.io/previous-attributes": "{\"labels\":{\"region\":\"beijing\"}}", @@ -276,7 +276,7 @@ func TestReconcile(t *testing.T) { if len(tc.wantedNodes) != 0 { var currentNodeList corev1.NodeList if err := r.List(ctx, ¤tNodeList, client.MatchingLabels(map[string]string{ - apps.NodePoolLabel: tc.pool, + projectinfo.GetNodePoolLabel(): tc.pool, })); err != nil { t.Errorf("Reconcile() error = %v", err) return diff --git a/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers.go b/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers.go index e84f89299f9..f3e533d5761 100644 --- a/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers.go +++ b/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers.go @@ -29,6 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) type EnqueueNodePoolForNode struct { @@ -46,7 +47,7 @@ func (e *EnqueueNodePoolForNode) Create(evt event.CreateEvent, } klog.V(5).Infof(Format("will enqueue nodepool as node(%s) has been created", node.GetName())) - if np := node.Labels[apps.NodePoolLabel]; len(np) != 0 { + if np := node.Labels[projectinfo.GetNodePoolLabel()]; len(np) != 0 { addNodePoolToWorkQueue(np, q) return } @@ -69,8 +70,8 @@ func (e *EnqueueNodePoolForNode) Update(evt event.UpdateEvent, return } - newNp := newNode.Labels[apps.NodePoolLabel] - oldNp := oldNode.Labels[apps.NodePoolLabel] + newNp := newNode.Labels[projectinfo.GetNodePoolLabel()] + oldNp := oldNode.Labels[projectinfo.GetNodePoolLabel()] // check the NodePoolLabel of node if len(oldNp) == 0 && len(newNp) == 0 { @@ -117,7 +118,7 @@ func (e *EnqueueNodePoolForNode) Delete(evt event.DeleteEvent, return } - np := node.Labels[apps.NodePoolLabel] + np := node.Labels[projectinfo.GetNodePoolLabel()] if len(np) == 0 { klog.V(4).Infof(Format("A orphan node(%s) is removed", node.Name)) return diff --git a/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers_test.go b/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers_test.go index 67ed2a6a706..90cabe4753e 100644 --- a/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers_test.go +++ b/pkg/yurtmanager/controller/nodepool/nodepool_enqueue_handlers_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/client-go/util/workqueue" "sigs.k8s.io/controller-runtime/pkg/event" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func TestCreate(t *testing.T) { @@ -50,7 +50,7 @@ func TestCreate(t *testing.T) { Object: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, @@ -104,7 +104,7 @@ func TestUpdate(t *testing.T) { ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, @@ -116,14 +116,14 @@ func TestUpdate(t *testing.T) { ObjectOld: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "bar", + projectinfo.GetNodePoolLabel(): "bar", }, }, }, @@ -135,14 +135,14 @@ func TestUpdate(t *testing.T) { ObjectOld: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, @@ -154,7 +154,7 @@ func TestUpdate(t *testing.T) { ObjectOld: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, Status: corev1.NodeStatus{ @@ -169,7 +169,7 @@ func TestUpdate(t *testing.T) { ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, Status: corev1.NodeStatus{ @@ -189,7 +189,7 @@ func TestUpdate(t *testing.T) { ObjectOld: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, Status: corev1.NodeStatus{ @@ -204,7 +204,7 @@ func TestUpdate(t *testing.T) { ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, Status: corev1.NodeStatus{ @@ -224,8 +224,8 @@ func TestUpdate(t *testing.T) { ObjectOld: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", - "label1": "value1", + projectinfo.GetNodePoolLabel(): "foo", + "label1": "value1", }, }, Status: corev1.NodeStatus{ @@ -240,8 +240,8 @@ func TestUpdate(t *testing.T) { ObjectNew: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", - "label2": "value2", + projectinfo.GetNodePoolLabel(): "foo", + "label2": "value2", }, }, Status: corev1.NodeStatus{ @@ -296,7 +296,7 @@ func TestDelete(t *testing.T) { Object: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "foo", + projectinfo.GetNodePoolLabel(): "foo", }, }, }, diff --git a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go index 6cf7645060b..840d7a2509e 100644 --- a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go +++ b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go @@ -46,10 +46,10 @@ import ( appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config" "github.com/openyurtio/openyurt/cmd/yurt-manager/names" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" iotv1alpha2 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2" + "github.com/openyurtio/openyurt/pkg/projectinfo" "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config" util "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/utils" ) @@ -454,7 +454,7 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor } pool.NodeSelectorTerm.MatchExpressions = append(pool.NodeSelectorTerm.MatchExpressions, corev1.NodeSelectorRequirement{ - Key: apps.NodePoolLabel, + Key: projectinfo.GetNodePoolLabel(), Operator: corev1.NodeSelectorOpIn, Values: []string{platformAdmin.Spec.PoolName}, }) @@ -572,7 +572,7 @@ func (r *ReconcilePlatformAdmin) handleYurtAppSet(ctx context.Context, platformA } pool.NodeSelectorTerm.MatchExpressions = append(pool.NodeSelectorTerm.MatchExpressions, corev1.NodeSelectorRequirement{ - Key: apps.NodePoolLabel, + Key: projectinfo.GetNodePoolLabel(), Operator: corev1.NodeSelectorOpIn, Values: []string{platformAdmin.Spec.PoolName}, }) diff --git a/pkg/yurtmanager/controller/raven/dns/dns_controller.go b/pkg/yurtmanager/controller/raven/dns/dns_controller.go index 8ffe41129bb..0ab7edde1d0 100644 --- a/pkg/yurtmanager/controller/raven/dns/dns_controller.go +++ b/pkg/yurtmanager/controller/raven/dns/dns_controller.go @@ -121,21 +121,19 @@ func (r *ReconcileDns) Reconcile(ctx context.Context, req reconcile.Request) (re // 2. acquired raven global config to check whether the proxy s enabled enableProxy, _ := util.CheckServer(ctx, r.Client) if !enableProxy { - r.recorder.Event(cm.DeepCopy(), corev1.EventTypeNormal, "MaintainDNSRecord", "The Raven Layer 7 proxy feature is not enabled for the cluster") + klog.Infoln(Format("the proxy feature is not enabled for the cluster")) } else { svc, err := r.getService(ctx, types.NamespacedName{Namespace: util.WorkingNamespace, Name: util.GatewayProxyInternalService}) if err != nil && !apierrors.IsNotFound(err) { - klog.V(2).Infof(Format("could not get service %s/%s", util.WorkingNamespace, util.GatewayProxyInternalService)) + klog.Errorf(Format("could not get service %s/%s", util.WorkingNamespace, util.GatewayProxyInternalService)) return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, err } if apierrors.IsNotFound(err) || svc.DeletionTimestamp != nil { - r.recorder.Event(cm.DeepCopy(), corev1.EventTypeNormal, "MaintainDNSRecord", - fmt.Sprintf("The Raven Layer 7 proxy lacks service %s/%s", util.WorkingNamespace, util.GatewayProxyInternalService)) + klog.Infoln(Format("the proxy feature lacks service %s/%s", util.WorkingNamespace, util.GatewayProxyInternalService)) } if svc != nil { if svc.Spec.ClusterIP == "" { - r.recorder.Event(cm.DeepCopy(), corev1.EventTypeNormal, "MaintainDNSRecord", - fmt.Sprintf("The service %s/%s cluster IP is empty", util.WorkingNamespace, util.GatewayProxyInternalService)) + klog.Infoln("the service %s/%s cluster IP is empty", util.WorkingNamespace, util.GatewayProxyInternalService) } else { proxyAddress = svc.Spec.ClusterIP } @@ -143,16 +141,18 @@ func (r *ReconcileDns) Reconcile(ctx context.Context, req reconcile.Request) (re } //3. update dns record - nodeList := new(corev1.NodeList) - err = r.Client.List(ctx, nodeList, &client.ListOptions{}) + nodeList := corev1.NodeList{} + err = r.Client.List(ctx, &nodeList, &client.ListOptions{}) if err != nil { - return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, fmt.Errorf("could not list node, error %s", err.Error()) + klog.Errorf(Format("could not list node, error %s", err.Error())) + return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, err } - cm.Data[util.ProxyNodesKey] = buildDNSRecords(nodeList, enableProxy, proxyAddress) + cm.Data[util.ProxyNodesKey] = buildDNSRecords(&nodeList, enableProxy, proxyAddress) err = r.updateDNS(cm) if err != nil { - return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, fmt.Errorf("could not update configmap %s/%s, error %s", - cm.GetNamespace(), cm.GetName(), err.Error()) + klog.Errorf(Format("could not update configmap %s/%s, error %s", + cm.GetNamespace(), cm.GetName(), err.Error())) + return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, err } return reconcile.Result{}, nil } @@ -218,7 +218,7 @@ func (r *ReconcileDns) updateDNS(cm *corev1.ConfigMap) error { func buildDNSRecords(nodeList *corev1.NodeList, needProxy bool, proxyIp string) string { // record node name <-> ip address if needProxy && proxyIp == "" { - klog.Errorf(Format("internal proxy address is empty for dns record, redirect node internal address")) + klog.Infoln(Format("internal proxy address is empty for dns record, redirect node internal address")) needProxy = false } var err error diff --git a/pkg/yurtmanager/controller/raven/dns/dns_enqueue_handlers.go b/pkg/yurtmanager/controller/raven/dns/dns_enqueue_handlers.go index 624e1e7ab4c..3faedc77cfe 100644 --- a/pkg/yurtmanager/controller/raven/dns/dns_enqueue_handlers.go +++ b/pkg/yurtmanager/controller/raven/dns/dns_enqueue_handlers.go @@ -38,7 +38,7 @@ func (h *EnqueueRequestForServiceEvent) Create(e event.CreateEvent, q workqueue. return } - klog.V(2).Infof(Format("enqueue configmap %s/%s due to service create event", util.WorkingNamespace, util.RavenProxyNodesConfig)) + klog.V(4).Infof(Format("enqueue configmap %s/%s due to service create event", util.WorkingNamespace, util.RavenProxyNodesConfig)) util.AddDNSConfigmapToWorkQueue(q) } @@ -54,7 +54,7 @@ func (h *EnqueueRequestForServiceEvent) Update(e event.UpdateEvent, q workqueue. return } if newSvc.Spec.ClusterIP != oldSvc.Spec.ClusterIP { - klog.V(2).Infof(Format("enqueue configmap %s/%s due to service update event", util.WorkingNamespace, util.RavenProxyNodesConfig)) + klog.V(4).Infof(Format("enqueue configmap %s/%s due to service update event", util.WorkingNamespace, util.RavenProxyNodesConfig)) util.AddDNSConfigmapToWorkQueue(q) } } @@ -65,7 +65,7 @@ func (h *EnqueueRequestForServiceEvent) Delete(e event.DeleteEvent, q workqueue. klog.Error(Format("could not assert runtime Object to v1.Service")) return } - klog.V(2).Infof(Format("enqueue configmap %s/%s due to service update event", util.WorkingNamespace, util.RavenProxyNodesConfig)) + klog.V(4).Infof(Format("enqueue configmap %s/%s due to service update event", util.WorkingNamespace, util.RavenProxyNodesConfig)) util.AddDNSConfigmapToWorkQueue(q) return } @@ -82,7 +82,7 @@ func (h *EnqueueRequestForNodeEvent) Create(e event.CreateEvent, q workqueue.Rat klog.Error(Format("could not assert runtime Object to v1.Node")) return } - klog.V(2).Infof(Format("enqueue configmap %s/%s due to node create event", util.WorkingNamespace, util.RavenProxyNodesConfig)) + klog.V(4).Infof(Format("enqueue configmap %s/%s due to node create event", util.WorkingNamespace, util.RavenProxyNodesConfig)) util.AddDNSConfigmapToWorkQueue(q) } @@ -96,7 +96,7 @@ func (h *EnqueueRequestForNodeEvent) Delete(e event.DeleteEvent, q workqueue.Rat klog.Error(Format("could not assert runtime Object to v1.Node")) return } - klog.V(2).Infof(Format("enqueue configmap %s/%s due to node delete event", util.WorkingNamespace, util.RavenProxyNodesConfig)) + klog.V(4).Infof(Format("enqueue configmap %s/%s due to node delete event", util.WorkingNamespace, util.RavenProxyNodesConfig)) util.AddDNSConfigmapToWorkQueue(q) } diff --git a/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_controller.go b/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_controller.go index c200b52d3ea..ac1ef010fc7 100644 --- a/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_controller.go +++ b/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_controller.go @@ -124,10 +124,6 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { // Reconcile reads that state of the cluster for a Gateway object and makes changes based on the state read // and what is in the Gateway.Spec func (r *ReconcileService) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { - klog.V(2).Info(Format("started reconciling Service %s/%s", req.Namespace, req.Name)) - defer func() { - klog.V(2).Info(Format("finished reconciling Service %s/%s", req.Namespace, req.Name)) - }() gwList, err := r.listExposedGateway(ctx) if err != nil { @@ -135,13 +131,15 @@ func (r *ReconcileService) Reconcile(ctx context.Context, req reconcile.Request) } enableProxy, _ := util.CheckServer(ctx, r.Client) - if err := r.reconcileService(ctx, req, gwList, enableProxy); err != nil { + if err = r.reconcileService(ctx, req, gwList, enableProxy); err != nil { err = fmt.Errorf(Format("unable to reconcile service: %s", err)) + klog.Errorln(err.Error()) return reconcile.Result{}, err } - if err := r.reconcileEndpoint(ctx, req, gwList, enableProxy); err != nil { + if err = r.reconcileEndpoint(ctx, req, gwList, enableProxy); err != nil { err = fmt.Errorf(Format("unable to reconcile endpoint: %s", err)) + klog.Errorln(err.Error()) return reconcile.Result{}, err } return reconcile.Result{}, nil @@ -168,9 +166,15 @@ func (r *ReconcileService) listExposedGateway(ctx context.Context) ([]*ravenv1be func (r *ReconcileService) reconcileService(ctx context.Context, req ctrl.Request, gatewayList []*ravenv1beta1.Gateway, enableProxy bool) error { if len(gatewayList) == 0 || !enableProxy { - return r.cleanService(ctx, req) + if err := r.cleanService(ctx, req); err != nil { + return fmt.Errorf("clear service %s error: %s", req.String(), err.Error()) + } + return nil + } + if err := r.updateService(ctx, req, gatewayList); err != nil { + return fmt.Errorf("update service %s error: %s", req.String(), err.Error()) } - return r.updateService(ctx, req, gatewayList) + return nil } func (r *ReconcileService) cleanService(ctx context.Context, req ctrl.Request) error { @@ -285,12 +289,18 @@ func (r *ReconcileService) reconcileEndpoint(ctx context.Context, req ctrl.Reque var service corev1.Service err := r.Get(ctx, req.NamespacedName, &service) if err != nil && !apierrs.IsNotFound(err) { - return err + return fmt.Errorf("get service %s, error: %s", req.String(), err.Error()) } if apierrs.IsNotFound(err) || service.DeletionTimestamp != nil || len(gatewayList) == 0 || !enableProxy { - return r.cleanEndpoint(ctx, req) + if err = r.cleanEndpoint(ctx, req); err != nil { + return fmt.Errorf("clear endpoints %s, error: %s", req.String(), err.Error()) + } + return nil } - return r.updateEndpoint(ctx, req, &service, gatewayList) + if err = r.updateEndpoint(ctx, req, &service, gatewayList); err != nil { + return fmt.Errorf("update endpoints %s, error: %s", req.String(), err.Error()) + } + return nil } func (r *ReconcileService) cleanEndpoint(ctx context.Context, req ctrl.Request) error { diff --git a/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go b/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go index d1a0f9e1e04..4e473502e88 100644 --- a/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go +++ b/pkg/yurtmanager/controller/raven/gatewayinternalservice/gateway_internal_service_enqueue_handlers.go @@ -39,7 +39,7 @@ func (h *EnqueueRequestForGatewayEvent) Create(e event.CreateEvent, q workqueue. if gw.Spec.ExposeType == "" { return } - klog.V(2).Infof(Format("enqueue service %s/%s due to gateway %s create event", util.WorkingNamespace, util.GatewayProxyInternalService, gw.GetName())) + klog.V(4).Infof(Format("enqueue service %s/%s due to gateway %s create event", util.WorkingNamespace, util.GatewayProxyInternalService, gw.GetName())) util.AddGatewayProxyInternalService(q) } @@ -57,7 +57,7 @@ func (h *EnqueueRequestForGatewayEvent) Update(e event.UpdateEvent, q workqueue. if oldGw.Spec.ExposeType == "" && newGw.Spec.ExposeType == "" { return } - klog.V(2).Infof(Format("enqueue service %s/%s due to gateway %s update event", util.WorkingNamespace, util.GatewayProxyInternalService, newGw.GetName())) + klog.V(4).Infof(Format("enqueue service %s/%s due to gateway %s update event", util.WorkingNamespace, util.GatewayProxyInternalService, newGw.GetName())) util.AddGatewayProxyInternalService(q) } @@ -70,7 +70,7 @@ func (h *EnqueueRequestForGatewayEvent) Delete(e event.DeleteEvent, q workqueue. if gw.Spec.ExposeType == "" { return } - klog.V(2).Infof(Format("enqueue service %s/%s due to gateway %s delete event", util.WorkingNamespace, util.GatewayProxyInternalService, gw.GetName())) + klog.V(4).Infof(Format("enqueue service %s/%s due to gateway %s delete event", util.WorkingNamespace, util.GatewayProxyInternalService, gw.GetName())) util.AddGatewayProxyInternalService(q) } @@ -91,14 +91,14 @@ func (h *EnqueueRequestForConfigEvent) Create(e event.CreateEvent, q workqueue.R } _, _, err := net.SplitHostPort(cm.Data[util.ProxyServerInsecurePortKey]) if err == nil { - klog.V(2).Infof(Format("enqueue service %s/%s due to config %s/%s create event", + klog.V(4).Infof(Format("enqueue service %s/%s due to config %s/%s create event", util.WorkingNamespace, util.GatewayProxyInternalService, util.WorkingNamespace, util.RavenAgentConfig)) util.AddGatewayProxyInternalService(q) return } _, _, err = net.SplitHostPort(cm.Data[util.ProxyServerSecurePortKey]) if err == nil { - klog.V(2).Infof(Format("enqueue service %s/%s due to config %s/%s create event", + klog.V(4).Infof(Format("enqueue service %s/%s due to config %s/%s create event", util.WorkingNamespace, util.GatewayProxyInternalService, util.WorkingNamespace, util.RavenAgentConfig)) util.AddGatewayProxyInternalService(q) return @@ -120,7 +120,7 @@ func (h *EnqueueRequestForConfigEvent) Update(e event.UpdateEvent, q workqueue.R _, oldInsecurePort, oldErr := net.SplitHostPort(oldCm.Data[util.ProxyServerInsecurePortKey]) if newErr == nil && oldErr == nil { if newInsecurePort != oldInsecurePort { - klog.V(2).Infof(Format("enqueue service %s/%s due to config %s/%s update event", + klog.V(4).Infof(Format("enqueue service %s/%s due to config %s/%s update event", util.WorkingNamespace, util.GatewayProxyInternalService, util.WorkingNamespace, util.RavenAgentConfig)) util.AddGatewayProxyInternalService(q) return @@ -130,7 +130,7 @@ func (h *EnqueueRequestForConfigEvent) Update(e event.UpdateEvent, q workqueue.R _, oldSecurePort, oldErr := net.SplitHostPort(oldCm.Data[util.ProxyServerSecurePortKey]) if newErr == nil && oldErr == nil { if newSecurePort != oldSecurePort { - klog.V(2).Infof(Format("enqueue service %s/%s due to config %s/%s update event", + klog.V(4).Infof(Format("enqueue service %s/%s due to config %s/%s update event", util.WorkingNamespace, util.GatewayProxyInternalService, util.WorkingNamespace, util.RavenAgentConfig)) util.AddGatewayProxyInternalService(q) return diff --git a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go index ed22958459b..79b03829ccb 100644 --- a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go +++ b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go @@ -150,16 +150,9 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { // and what is in the Gateway.Spec func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { - // Note !!!!!!!!!! - // We strongly recommend use Format() to encapsulation because Format() can print logs by module - // @kadisi - klog.V(2).Info(Format("started reconciling Gateway %s/%s", req.Namespace, req.Name)) - defer func() { - klog.V(2).Info(Format("finished reconciling Gateway %s/%s", req.Namespace, req.Name)) - }() - var gw ravenv1beta1.Gateway if err := r.Get(ctx, req.NamespacedName, &gw); err != nil { + klog.Error(Format("unable get gateway %s, error %s", req.String(), err.Error())) return reconcile.Result{}, client.IgnoreNotFound(err) } @@ -169,14 +162,12 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request) if err != nil { return reconcile.Result{}, err } - err = r.List(ctx, &nodeList, &client.ListOptions{ - LabelSelector: nodeSelector, - }) + err = r.List(ctx, &nodeList, &client.ListOptions{LabelSelector: nodeSelector}) if err != nil { - err = fmt.Errorf("unable to list nodes: %s", err) + klog.Error(Format("unable to list node error %s", err.Error())) return reconcile.Result{}, err } - klog.V(1).Info(Format("list gateway %d node %v", len(nodeList.Items), nodeList.Items)) + // 1. try to elect an active endpoint if possible activeEp := r.electActiveEndpoint(nodeList, &gw) r.recordEndpointEvent(&gw, gw.Status.ActiveEndpoints, activeEp) @@ -187,7 +178,7 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request) for _, v := range nodeList.Items { podCIDRs, err := r.getPodCIDRs(ctx, v) if err != nil { - klog.ErrorS(err, "unable to get podCIDR") + klog.Error(Format("unable to get podCIDR for node %s error %s", v.GetName(), err.Error())) return reconcile.Result{}, err } nodes = append(nodes, ravenv1beta1.NodeInfo{ @@ -197,7 +188,6 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request) }) } sort.Slice(nodes, func(i, j int) bool { return nodes[i].NodeName < nodes[j].NodeName }) - klog.V(4).Info(Format("managed node info list, nodes: %v", nodes)) gw.Status.Nodes = nodes err = r.Status().Update(ctx, &gw) if err != nil { @@ -205,8 +195,8 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request) klog.Warning(err, Format("unable to update gateway.status, error %s", err.Error())) return reconcile.Result{Requeue: true, RequeueAfter: 5 * time.Second}, nil } - return reconcile.Result{Requeue: true, RequeueAfter: 5 * time.Second}, - fmt.Errorf("unable to update %s gateway.status, error %s", gw.GetName(), err.Error()) + klog.Error(Format("unable to update %s gateway.status, error %s", gw.GetName(), err.Error())) + return reconcile.Result{Requeue: true, RequeueAfter: 5 * time.Second}, err } return reconcile.Result{}, nil } diff --git a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_enqueue_handlers.go b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_enqueue_handlers.go index d2acf9016f1..b092285a992 100644 --- a/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_enqueue_handlers.go +++ b/pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_enqueue_handlers.go @@ -133,7 +133,7 @@ func (e *EnqueueGatewayForRavenConfig) Update(evt event.UpdateEvent, q workqueue } if oldCm.Data[util.RavenEnableProxy] != newCm.Data[util.RavenEnableProxy] { - klog.V(2).Infof(Format("Will config all gateway as raven-cfg has been updated")) + klog.V(4).Infof(Format("Will config all gateway as raven-cfg has been updated")) if err := e.enqueueGateways(q); err != nil { klog.Error(Format("could not config all gateway, error %s", err.Error())) return @@ -141,7 +141,7 @@ func (e *EnqueueGatewayForRavenConfig) Update(evt event.UpdateEvent, q workqueue } if oldCm.Data[util.RavenEnableTunnel] != newCm.Data[util.RavenEnableTunnel] { - klog.V(2).Infof(Format("Will config all gateway as raven-cfg has been updated")) + klog.V(4).Infof(Format("Will config all gateway as raven-cfg has been updated")) if err := e.enqueueGateways(q); err != nil { klog.Error(Format("could not config all gateway, error %s", err.Error())) return @@ -155,7 +155,7 @@ func (e *EnqueueGatewayForRavenConfig) Delete(evt event.DeleteEvent, q workqueue klog.Error(Format("could not assert runtime Object to v1.ConfigMap")) return } - klog.V(2).Infof(Format("Will config all gateway as raven-cfg has been deleted")) + klog.V(4).Infof(Format("Will config all gateway as raven-cfg has been deleted")) if err := e.enqueueGateways(q); err != nil { klog.Error(Format("could not config all gateway, error %s", err.Error())) return diff --git a/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_controller.go b/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_controller.go index 958cd4948da..28ed6b81820 100644 --- a/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_controller.go +++ b/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_controller.go @@ -135,9 +135,6 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { // Reconcile reads that state of the cluster for a Gateway object and makes changes based on the state read // and what is in the Gateway.Spec func (r *ReconcileService) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { - klog.V(2).Info(Format("started reconciling public service for gateway %s", req.Name)) - defer klog.V(2).Info(Format("finished reconciling public service for gateway %s", req.Name)) - enableProxy, enableTunnel := util.CheckServer(ctx, r.Client) gw, err := r.getGateway(ctx, req) if err != nil { @@ -159,6 +156,7 @@ func (r *ReconcileService) Reconcile(ctx context.Context, req reconcile.Request) if err := r.reconcileEndpoints(ctx, gw.DeepCopy(), svcRecord, enableTunnel, enableProxy); err != nil { err = fmt.Errorf(Format("unable to reconcile endpoint: %s", err)) + klog.Error(err.Error()) return reconcile.Result{Requeue: true, RequeueAfter: 2 * time.Second}, err } return reconcile.Result{}, nil @@ -187,30 +185,22 @@ func recordServiceNames(services []corev1.Service, record *serviceRecord) { func (r *ReconcileService) reconcileService(ctx context.Context, gw *ravenv1beta1.Gateway, record *serviceRecord, enableTunnel, enableProxy bool) error { if enableProxy { - klog.V(2).Info(Format("start manage proxy service for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish manage proxy service for gateway %s", gw.GetName())) if err := r.manageService(ctx, gw, ravenv1beta1.Proxy, record); err != nil { - return fmt.Errorf("could not manage service for proxy server %s", err.Error()) + return fmt.Errorf("could not manage service for proxy, error %s", err.Error()) } } else { - klog.V(2).Info(Format("start clear proxy service for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish clear proxy service for gateway %s", gw.GetName())) if err := r.clearService(ctx, gw.GetName(), ravenv1beta1.Proxy); err != nil { - return fmt.Errorf("could not clear service for proxy server %s", err.Error()) + return fmt.Errorf("could not clear service for proxy, error %s", err.Error()) } } if enableTunnel { - klog.V(2).Info(Format("start manage tunnel service for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish manage tunnel service for gateway %s", gw.GetName())) if err := r.manageService(ctx, gw, ravenv1beta1.Tunnel, record); err != nil { - return fmt.Errorf("could not manage service for tunnel server %s", err.Error()) + return fmt.Errorf("could not manage service for tunnel, error %s", err.Error()) } } else { - klog.V(2).Info(Format("start clear tunnel service for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish clear tunnel service for gateway %s", gw.GetName())) if err := r.clearService(ctx, gw.GetName(), ravenv1beta1.Tunnel); err != nil { - return fmt.Errorf("could not clear service for tunnel server %s", err.Error()) + return fmt.Errorf("could not clear service for tunnel, error %s", err.Error()) } } return nil @@ -218,27 +208,19 @@ func (r *ReconcileService) reconcileService(ctx context.Context, gw *ravenv1beta func (r *ReconcileService) reconcileEndpoints(ctx context.Context, gw *ravenv1beta1.Gateway, record *serviceRecord, enableTunnel, enableProxy bool) error { if enableProxy { - klog.V(2).Info(Format("start manage proxy service endpoints for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish manage proxy service endpoints for gateway %s", gw.GetName())) if err := r.manageEndpoints(ctx, gw, ravenv1beta1.Proxy, record); err != nil { return fmt.Errorf("could not manage endpoints for proxy server %s", err.Error()) } } else { - klog.V(2).Info(Format("start clear proxy service endpoints for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish clear proxy service endpoints for gateway %s", gw.GetName())) if err := r.clearEndpoints(ctx, gw.GetName(), ravenv1beta1.Proxy); err != nil { return fmt.Errorf("could not clear endpoints for proxy server %s", err.Error()) } } if enableTunnel { - klog.V(2).Info(Format("start manage tunnel service endpoints for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish manage tunnel service endpoints for gateway %s", gw.GetName())) if err := r.manageEndpoints(ctx, gw, ravenv1beta1.Tunnel, record); err != nil { return fmt.Errorf("could not manage endpoints for tunnel server %s", err.Error()) } } else { - klog.V(2).Info(Format("start clear tunnel service endpoints for gateway %s", gw.GetName())) - defer klog.V(2).Info(Format("finish clear tunnel service endpoints for gateway %s", gw.GetName())) if err := r.clearEndpoints(ctx, gw.GetName(), ravenv1beta1.Tunnel); err != nil { return fmt.Errorf("could not clear endpoints for tunnel server %s", err.Error()) } diff --git a/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_enqueue_handlers.go b/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_enqueue_handlers.go index 0cf1528d800..bce68bb8645 100644 --- a/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_enqueue_handlers.go +++ b/pkg/yurtmanager/controller/raven/gatewaypublicservice/gateway_public_service_enqueue_handlers.go @@ -41,7 +41,7 @@ func (h *EnqueueRequestForGatewayEvent) Create(e event.CreateEvent, q workqueue. if gw.Spec.ExposeType != ravenv1beta1.ExposeTypeLoadBalancer { return } - klog.V(2).Infof(Format("enqueue gateway %s as create event", gw.GetName())) + klog.V(4).Infof(Format("enqueue gateway %s as create event", gw.GetName())) util.AddGatewayToWorkQueue(gw.GetName(), q) } @@ -57,7 +57,7 @@ func (h *EnqueueRequestForGatewayEvent) Update(e event.UpdateEvent, q workqueue. return } if needUpdate(newGw, oldGw) { - klog.V(2).Infof(Format("enqueue gateway %s as update event", newGw.GetName())) + klog.V(4).Infof(Format("enqueue gateway %s as update event", newGw.GetName())) util.AddGatewayToWorkQueue(newGw.GetName(), q) } } @@ -71,7 +71,7 @@ func (h *EnqueueRequestForGatewayEvent) Delete(e event.DeleteEvent, q workqueue. if gw.Spec.ExposeType != ravenv1beta1.ExposeTypeLoadBalancer { return } - klog.V(2).Infof(Format("enqueue gateway %s as delete event", gw.GetName())) + klog.V(4).Infof(Format("enqueue gateway %s as delete event", gw.GetName())) util.AddGatewayToWorkQueue(gw.GetName(), q) } @@ -155,7 +155,7 @@ func addExposedGateway(client client.Client, q workqueue.RateLimitingInterface) } for _, gw := range gwList.Items { if gw.Spec.ExposeType == ravenv1beta1.ExposeTypeLoadBalancer { - klog.V(2).Infof(Format("enqueue gateway %s", gw.GetName())) + klog.V(4).Infof(Format("enqueue gateway %s", gw.GetName())) util.AddGatewayToWorkQueue(gw.GetName(), q) } } diff --git a/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util.go b/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util.go index eb0bedd6948..e62a348d28d 100644 --- a/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util.go +++ b/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/validation" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func getWorkloadPrefix(controllerName, nodepoolName string) string { @@ -35,7 +35,7 @@ func getWorkloadPrefix(controllerName, nodepoolName string) string { func CreateNodeSelectorByNodepoolName(nodepool string) map[string]string { return map[string]string{ - apps.NodePoolLabel: nodepool, + projectinfo.GetNodePoolLabel(): nodepool, } } diff --git a/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util_test.go b/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util_test.go index 96a1493fcb9..5492d4ea7ee 100644 --- a/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util_test.go +++ b/pkg/yurtmanager/controller/yurtappdaemon/workloadcontroller/util_test.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" - "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) const ( @@ -67,7 +67,7 @@ func TestCreateNodeSelectorByNodepoolName(t *testing.T) { "normal", "a", map[string]string{ - apps.NodePoolLabel: "a", + projectinfo.GetNodePoolLabel(): "a", }, }, } diff --git a/pkg/yurtmanager/webhook/node/v1/node_default.go b/pkg/yurtmanager/webhook/node/v1/node_default.go index 52bbf692e3a..ec967896853 100644 --- a/pkg/yurtmanager/webhook/node/v1/node_default.go +++ b/pkg/yurtmanager/webhook/node/v1/node_default.go @@ -19,7 +19,6 @@ package v1 import ( "context" "fmt" - "strings" v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -29,6 +28,7 @@ import ( "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) // Default satisfies the defaulting webhook interface. @@ -38,11 +38,11 @@ func (webhook *NodeHandler) Default(ctx context.Context, obj runtime.Object, req return apierrors.NewBadRequest(fmt.Sprintf("expected a Node but got a %T", obj)) } - npName := node.Labels[apps.NodePoolLabel] + npName := node.Labels[projectinfo.GetNodePoolLabel()] if len(npName) == 0 { npName = node.Labels[apps.DesiredNodePoolLabel] if len(npName) != 0 { - node.Labels[apps.NodePoolLabel] = npName + node.Labels[projectinfo.GetNodePoolLabel()] = npName } else { return nil } @@ -57,7 +57,6 @@ func (webhook *NodeHandler) Default(ctx context.Context, obj runtime.Object, req if node.Labels == nil { node.Labels = make(map[string]string) } - node.Labels[apps.NodePoolTypeLabel] = strings.ToLower(string(np.Spec.Type)) if np.Spec.HostNetwork { node.Labels[apps.NodePoolHostNetworkLabel] = "true" diff --git a/pkg/yurtmanager/webhook/node/v1/node_default_test.go b/pkg/yurtmanager/webhook/node/v1/node_default_test.go index 76d0679bf3c..7ff73778cab 100644 --- a/pkg/yurtmanager/webhook/node/v1/node_default_test.go +++ b/pkg/yurtmanager/webhook/node/v1/node_default_test.go @@ -32,8 +32,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" "github.com/openyurtio/openyurt/pkg/apis" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func TestDefault(t *testing.T) { @@ -56,7 +56,7 @@ func TestDefault(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, @@ -68,7 +68,7 @@ func TestDefault(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo", Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, diff --git a/pkg/yurtmanager/webhook/node/v1/node_validation.go b/pkg/yurtmanager/webhook/node/v1/node_validation.go index 7ee9f6c1e80..cd7262914a8 100644 --- a/pkg/yurtmanager/webhook/node/v1/node_validation.go +++ b/pkg/yurtmanager/webhook/node/v1/node_validation.go @@ -27,6 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type. @@ -58,22 +59,15 @@ func (webhook *NodeHandler) ValidateDelete(_ context.Context, obj runtime.Object } func validateNodeUpdate(newNode, oldNode *v1.Node, req admission.Request) field.ErrorList { - oldNp := oldNode.Labels[apps.NodePoolLabel] - newNp := newNode.Labels[apps.NodePoolLabel] - oldNpType := oldNode.Labels[apps.NodePoolTypeLabel] - newNpType := newNode.Labels[apps.NodePoolTypeLabel] + oldNp := oldNode.Labels[projectinfo.GetNodePoolLabel()] + newNp := newNode.Labels[projectinfo.GetNodePoolLabel()] oldNpHostNetwork := oldNode.Labels[apps.NodePoolHostNetworkLabel] newNpHostNetwork := newNode.Labels[apps.NodePoolHostNetworkLabel] var errList field.ErrorList // it is not allowed to change NodePoolLabel if it has been set if len(oldNp) != 0 && oldNp != newNp { - errList = append(errList, field.Forbidden(field.NewPath("metadata").Child("labels").Child(apps.NodePoolLabel), "apps.openyurt.io/nodepool can not be changed")) - } - - // it is not allowed to change NodePoolTypeLabel if it has been set - if len(oldNpType) != 0 && oldNpType != newNpType { - errList = append(errList, field.Forbidden(field.NewPath("metadata").Child("labels").Child(apps.NodePoolTypeLabel), "nodepool.openyurt.io/type can not be changed")) + errList = append(errList, field.Forbidden(field.NewPath("metadata").Child("labels").Child(projectinfo.GetNodePoolLabel()), "apps.openyurt.io/nodepool can not be changed")) } // it is not allowed to change NodePoolHostNetworkLabel if it has been set diff --git a/pkg/yurtmanager/webhook/node/v1/node_validation_test.go b/pkg/yurtmanager/webhook/node/v1/node_validation_test.go index 6aa88d3d0e8..d8f8253a25d 100644 --- a/pkg/yurtmanager/webhook/node/v1/node_validation_test.go +++ b/pkg/yurtmanager/webhook/node/v1/node_validation_test.go @@ -28,6 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" "github.com/openyurtio/openyurt/pkg/apis/apps" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func TestValidateUpdate(t *testing.T) { @@ -50,33 +51,14 @@ func TestValidateUpdate(t *testing.T) { oldNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, }, newNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "shanghai", - }, - }, - }, - errCode: http.StatusUnprocessableEntity, - }, - "node pool type is changed": { - oldNode: &corev1.Node{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - }, - }, - }, - newNode: &corev1.Node{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "cloud", + projectinfo.GetNodePoolLabel(): "shanghai", }, }, }, @@ -86,18 +68,16 @@ func TestValidateUpdate(t *testing.T) { oldNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - apps.NodePoolHostNetworkLabel: "true", + projectinfo.GetNodePoolLabel(): "hangzhou", + apps.NodePoolHostNetworkLabel: "true", }, }, }, newNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - apps.NodePoolHostNetworkLabel: "false", + projectinfo.GetNodePoolLabel(): "hangzhou", + apps.NodePoolHostNetworkLabel: "false", }, }, }, @@ -107,18 +87,16 @@ func TestValidateUpdate(t *testing.T) { oldNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - apps.NodePoolHostNetworkLabel: "true", + projectinfo.GetNodePoolLabel(): "hangzhou", + apps.NodePoolHostNetworkLabel: "true", }, }, }, newNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - apps.NodePoolHostNetworkLabel: "true", + projectinfo.GetNodePoolLabel(): "hangzhou", + apps.NodePoolHostNetworkLabel: "true", }, }, }, @@ -129,9 +107,8 @@ func TestValidateUpdate(t *testing.T) { newNode: &corev1.Node{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", - apps.NodePoolTypeLabel: "edge", - apps.NodePoolHostNetworkLabel: "true", + projectinfo.GetNodePoolLabel(): "hangzhou", + apps.NodePoolHostNetworkLabel: "true", }, }, }, diff --git a/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation.go b/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation.go index f3661a4e109..08474f54693 100644 --- a/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation.go +++ b/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation.go @@ -28,8 +28,8 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) // ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type. @@ -137,7 +137,7 @@ func validateNodePoolSpecUpdate(spec, oldSpec *appsv1beta1.NodePoolSpec) field.E func validateNodePoolDeletion(cli client.Client, np *appsv1beta1.NodePool) field.ErrorList { nodes := corev1.NodeList{} - if err := cli.List(context.TODO(), &nodes, client.MatchingLabels(map[string]string{apps.NodePoolLabel: np.Name})); err != nil { + if err := cli.List(context.TODO(), &nodes, client.MatchingLabels(map[string]string{projectinfo.GetNodePoolLabel(): np.Name})); err != nil { return field.ErrorList([]*field.Error{ field.Forbidden(field.NewPath("metadata").Child("name"), "could not get nodes associated to the pool")}) diff --git a/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation_test.go b/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation_test.go index 0305d703225..b04b4d720c9 100644 --- a/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation_test.go +++ b/pkg/yurtmanager/webhook/nodepool/v1beta1/nodepool_validation_test.go @@ -30,8 +30,8 @@ import ( fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/openyurtio/openyurt/pkg/apis" - "github.com/openyurtio/openyurt/pkg/apis/apps" appsv1beta1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func TestValidateCreate(t *testing.T) { @@ -185,7 +185,7 @@ func prepareNodes() []client.Object { ObjectMeta: metav1.ObjectMeta{ Name: "node1", Labels: map[string]string{ - apps.NodePoolLabel: "hangzhou", + projectinfo.GetNodePoolLabel(): "hangzhou", }, }, Status: corev1.NodeStatus{ diff --git a/pkg/yurtmanager/webhook/util/configuration/configuration.go b/pkg/yurtmanager/webhook/util/configuration/configuration.go index 6c8e629ca91..6fa6786c53b 100644 --- a/pkg/yurtmanager/webhook/util/configuration/configuration.go +++ b/pkg/yurtmanager/webhook/util/configuration/configuration.go @@ -86,7 +86,7 @@ func Ensure(kubeClient clientset.Interface, handlers map[string]struct{}, caBund return err } if _, ok := handlers[path]; !ok { - klog.Warningf("Ignore webhook for %s in configuration", path) + klog.V(5).Infof("Ignore webhook for %s in configuration", path) continue } if wh.ClientConfig.Service != nil { diff --git a/test/e2e/util/nodepool.go b/test/e2e/util/nodepool.go index 3c3bfd1c789..0830f40cd1c 100644 --- a/test/e2e/util/nodepool.go +++ b/test/e2e/util/nodepool.go @@ -24,8 +24,8 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/openyurtio/openyurt/pkg/apis/apps" "github.com/openyurtio/openyurt/pkg/apis/apps/v1beta1" + "github.com/openyurtio/openyurt/pkg/projectinfo" ) func CleanupNodePool(ctx context.Context, k8sClient client.Client) error { @@ -52,8 +52,8 @@ func CleanupNodePoolLabel(ctx context.Context, k8sClient client.Client) error { newNode := originNode.DeepCopy() if newNode.Labels != nil { for k := range newNode.Labels { - if k == apps.NodePoolLabel { - delete(newNode.Labels, apps.NodePoolLabel) + if k == projectinfo.GetNodePoolLabel() { + delete(newNode.Labels, projectinfo.GetNodePoolLabel()) labelDeleted = true } } @@ -103,7 +103,7 @@ func InitNodeAndNodePool(ctx context.Context, k8sClient client.Client, poolToNod continue } - nodeLabels[apps.NodePoolLabel] = nodeToPoolMap[originNode.Name] + nodeLabels[projectinfo.GetNodePoolLabel()] = nodeToPoolMap[originNode.Name] newNode.Labels = nodeLabels if err := k8sClient.Patch(ctx, newNode, client.MergeFrom(&originNode)); err != nil { return err