Skip to content

Commit

Permalink
remove nodepool.openyurt.io/type label of node and improve apps.openy…
Browse files Browse the repository at this point in the history
…urt.io/nodepool label
  • Loading branch information
rambohe-ch committed Nov 22, 2023
1 parent 299c5f9 commit 2a06c2f
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 213 deletions.
1 change: 1 addition & 0 deletions hack/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 0 additions & 2 deletions pkg/apis/apps/well_known_labels_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
46 changes: 22 additions & 24 deletions pkg/projectinfo/projectinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
buildDate = "1970-01-01T00:00:00Z"
maintainingVersions = "unknown"
separator = ","
nodePoolLabelKey = "apps.openyurt.io/nodepool"
)

func ShortAgentVersion() string {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
}
}
4 changes: 2 additions & 2 deletions pkg/yurtadm/cmd/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 warning on line 358 in pkg/yurtadm/cmd/join/join.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtadm/cmd/join/join.go#L358

Added line #L358 was not covered by tests
}

// check static pods has value and yurtstaticset is already exist
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurthub/filter/hostnetworkpropagation/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/yurthub/filter/hostnetworkpropagation/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurthub/filter/nodeportisolation/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/yurthub/filter/nodeportisolation/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Annotations: map[string]string{
apps.NodePoolLabel: nodePoolName,
projectinfo.GetNodePoolLabel(): nodePoolName,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/yurthub/filter/servicetopology/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit 2a06c2f

Please sign in to comment.