Moved all custom naming into one place

This commit is contained in:
2026-04-03 01:48:07 +08:00
parent 3c0df319d7
commit 1ce15e9ac5
27 changed files with 87 additions and 103 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"os"
"undecided.project/monok8s/pkg/cmd/root"
"example.com/monok8s/pkg/cmd/root"
)
func main() {

View File

@@ -1,4 +1,4 @@
module undecided.project/monok8s
module example.com/monok8s
go 1.24.0

View File

@@ -6,12 +6,16 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
Group = "monok8s.io"
Version = "v1alpha1"
)
var (
Group = "monok8s.io"
Version = "v1alpha1"
MonoKSConfigCRD = "monoksconfigs.monok8s.io"
OSUpgradeCRD = "osupgrades.monok8s.io"
APIVersion = "monok8s.io/v1alpha1"
Label = "monok8s.io/label"
Annotation = "monok8s.io/annotation"
ControlAgentKey = "monok8s.io/control-agent"
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme

View File

@@ -3,7 +3,7 @@ package bootstrap
import (
"fmt"
"undecided.project/monok8s/pkg/node"
"example.com/monok8s/pkg/node"
)
type Registry struct {

View File

@@ -5,9 +5,9 @@ import (
"fmt"
"k8s.io/klog/v2"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
"undecided.project/monok8s/pkg/node"
"undecided.project/monok8s/pkg/system"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"example.com/monok8s/pkg/node"
"example.com/monok8s/pkg/system"
)
type Runner struct {

View File

@@ -11,10 +11,10 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
mkscmd "undecided.project/monok8s/pkg/cmd"
"undecided.project/monok8s/pkg/kube"
"undecided.project/monok8s/pkg/templates"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
mkscmd "example.com/monok8s/pkg/cmd"
"example.com/monok8s/pkg/kube"
"example.com/monok8s/pkg/templates"
)
func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
@@ -26,7 +26,7 @@ func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
Short: "Watch OSUpgrade resources and do nothing for now",
RunE: func(cmd *cobra.Command, _ []string) error {
var cfg *types.MonoKSConfig // or value, depending on your API
var cfg *monov1alpha1.MonoKSConfig // or value, depending on your API
if err := mkscmd.LoadEnvFile(envFile); err != nil {
return fmt.Errorf("load env file %q: %w", envFile, err)
@@ -41,7 +41,7 @@ func NewCmdAgent(flags *genericclioptions.ConfigFlags) *cobra.Command {
if err != nil {
return err
}
gvr := schema.GroupVersionResource{Group: types.Group, Version: types.Version, Resource: "osupgrades"}
gvr := schema.GroupVersionResource{Group: monov1alpha1.Group, Version: monov1alpha1.Version, Resource: "osupgrades"}
ctx := cmd.Context()
for {
list, err := clients.Dynamic.Resource(gvr).Namespace(namespace).List(ctx, metav1.ListOptions{})

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"undecided.project/monok8s/pkg/crds"
"undecided.project/monok8s/pkg/kube"
"example.com/monok8s/pkg/crds"
"example.com/monok8s/pkg/kube"
"github.com/spf13/cobra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"

View File

@@ -3,7 +3,7 @@ package checkconfig
import (
"fmt"
"undecided.project/monok8s/pkg/config"
"example.com/monok8s/pkg/config"
"github.com/spf13/cobra"
)

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/spf13/cobra"
render "undecided.project/monok8s/pkg/render"
render "example.com/monok8s/pkg/render"
)
func NewCmdCreate() *cobra.Command {

View File

@@ -10,12 +10,12 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
"undecided.project/monok8s/pkg/bootstrap"
"undecided.project/monok8s/pkg/config"
"example.com/monok8s/pkg/bootstrap"
"example.com/monok8s/pkg/config"
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
mkscmd "undecided.project/monok8s/pkg/cmd"
"undecided.project/monok8s/pkg/templates"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
mkscmd "example.com/monok8s/pkg/cmd"
"example.com/monok8s/pkg/templates"
)
func NewCmdInit(_ *genericclioptions.ConfigFlags) *cobra.Command {
@@ -69,7 +69,7 @@ Supported formats:
}
}
var cfg *types.MonoKSConfig // or value, depending on your API
var cfg *monov1alpha1.MonoKSConfig // or value, depending on your API
switch {
case strings.TrimSpace(envFile) != "":

View File

@@ -2,8 +2,8 @@ package internal
import (
"github.com/spf13/cobra"
"undecided.project/monok8s/pkg/bootstrap"
"undecided.project/monok8s/pkg/config"
"example.com/monok8s/pkg/bootstrap"
"example.com/monok8s/pkg/config"
)
func NewCmdInternal() *cobra.Command {

View File

@@ -7,13 +7,13 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
agentcmd "undecided.project/monok8s/pkg/cmd/agent"
applycmd "undecided.project/monok8s/pkg/cmd/apply"
checkconfigcmd "undecided.project/monok8s/pkg/cmd/checkconfig"
createcmd "undecided.project/monok8s/pkg/cmd/create"
initcmd "undecided.project/monok8s/pkg/cmd/initcmd"
internalcmd "undecided.project/monok8s/pkg/cmd/internal"
versioncmd "undecided.project/monok8s/pkg/cmd/version"
agentcmd "example.com/monok8s/pkg/cmd/agent"
applycmd "example.com/monok8s/pkg/cmd/apply"
checkconfigcmd "example.com/monok8s/pkg/cmd/checkconfig"
createcmd "example.com/monok8s/pkg/cmd/create"
initcmd "example.com/monok8s/pkg/cmd/initcmd"
internalcmd "example.com/monok8s/pkg/cmd/internal"
versioncmd "example.com/monok8s/pkg/cmd/version"
)
func init() {

View File

@@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
buildInfo "undecided.project/monok8s/pkg/buildinfo"
buildInfo "example.com/monok8s/pkg/buildinfo"
)
func NewCmdVersion() *cobra.Command {

View File

@@ -6,8 +6,8 @@ import (
"os"
"strings"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"gopkg.in/yaml.v3"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
)
const EnvVar = "MONOKSCONFIG"

View File

@@ -1,6 +1,7 @@
package crds
import (
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -14,9 +15,11 @@ func Definitions() []*apiextensionsv1.CustomResourceDefinition {
func monoKSConfigCRD() *apiextensionsv1.CustomResourceDefinition {
return &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: "monoksconfigs.monok8s.io"},
ObjectMeta: metav1.ObjectMeta{
Name: monov1alpha1.MonoKSConfigCRD,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: "monok8s.io",
Group: monov1alpha1.Group,
Scope: apiextensionsv1.NamespaceScoped,
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: "monoksconfigs",
@@ -42,9 +45,11 @@ func monoKSConfigCRD() *apiextensionsv1.CustomResourceDefinition {
func osUpgradeCRD() *apiextensionsv1.CustomResourceDefinition {
return &apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: "osupgrades.monok8s.io"},
ObjectMeta: metav1.ObjectMeta{
Name: monov1alpha1.OSUpgradeCRD,
},
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
Group: "monok8s.io",
Group: monov1alpha1.Group,
Scope: apiextensionsv1.NamespaceScoped,
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: "osupgrades",

View File

@@ -7,7 +7,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
kubernetes "k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions"

View File

@@ -14,14 +14,14 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/klog/v2"
"undecided.project/monok8s/pkg/crds"
"undecided.project/monok8s/pkg/kube"
templates "undecided.project/monok8s/pkg/templates"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"example.com/monok8s/pkg/crds"
"example.com/monok8s/pkg/kube"
templates "example.com/monok8s/pkg/templates"
)
const (
controlAgentName = "control-agent"
controlAgentNodeSelectorKey = "monok8s.io/control-agent"
controlAgentNodeSelectorValue = "true"
controlAgentImage = "localhost/monok8s/control-agent:dev"
kubeconfig = "/etc/kubernetes/admin.conf"
@@ -152,12 +152,12 @@ func applyControlAgentServiceAccount(ctx context.Context, kubeClient kubernetes.
func applyControlAgentClusterRole(ctx context.Context, kubeClient kubernetes.Interface, labels map[string]string) error {
wantRules := []rbacv1.PolicyRule{
{
APIGroups: []string{"monok8s.io"},
APIGroups: []string{monov1alpha1.Group},
Resources: []string{"osupgrades"},
Verbs: []string{"get", "list", "watch"},
},
{
APIGroups: []string{"monok8s.io"},
APIGroups: []string{monov1alpha1.Group},
Resources: []string{"osupgrades/status"},
Verbs: []string{"get", "patch", "update"},
},
@@ -290,7 +290,7 @@ func applyControlAgentDaemonSet(ctx context.Context, kubeClient kubernetes.Inter
HostPID: true,
DNSPolicy: corev1.DNSClusterFirstWithHostNet,
NodeSelector: map[string]string{
controlAgentNodeSelectorKey: controlAgentNodeSelectorValue,
monov1alpha1.ControlAgentKey: controlAgentNodeSelectorValue,
},
Tolerations: []corev1.Toleration{
{Operator: corev1.TolerationOpExists},

View File

@@ -3,8 +3,8 @@ package node
import (
"context"
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
"undecided.project/monok8s/pkg/system"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"example.com/monok8s/pkg/system"
)
type Step func(context.Context, *NodeContext) error

View File

@@ -7,7 +7,7 @@ import (
"strings"
"k8s.io/klog/v2"
system "undecided.project/monok8s/pkg/system"
system "example.com/monok8s/pkg/system"
)
func ConfigureDefaultCNI(ctx context.Context, n *NodeContext) error {

View File

@@ -17,8 +17,8 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
system "undecided.project/monok8s/pkg/system"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
system "example.com/monok8s/pkg/system"
)
const (
@@ -482,7 +482,7 @@ func normalizeKubeVersion(v string) string {
return v
}
func buildNodeRegistration(spec types.MonoKSConfigSpec) NodeRegistrationOptions {
func buildNodeRegistration(spec monov1alpha1.MonoKSConfigSpec) NodeRegistrationOptions {
nodeName := strings.TrimSpace(spec.NodeName)
criSocket := strings.TrimSpace(spec.ContainerRuntimeEndpoint)
advertiseAddress := strings.TrimSpace(spec.APIServerAdvertiseAddress)

View File

@@ -8,7 +8,7 @@ import (
"strings"
"time"
system "undecided.project/monok8s/pkg/system"
system "example.com/monok8s/pkg/system"
)
func StartKubelet(ctx context.Context, n *NodeContext) error {

View File

@@ -9,6 +9,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
monov1alpah1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubernetes "k8s.io/client-go/kubernetes"
)
@@ -63,7 +64,7 @@ func ApplyLocalNodeMetadataIfPossible(ctx context.Context, nctx *NodeContext) er
// Additional Labels
if spec.EnableControlAgent {
node.Labels[controlAgentNodeSelectorKey] = controlAgentNodeSelectorValue
node.Labels[monov1alpah1.ControlAgentKey] = controlAgentNodeSelectorValue
}
// Apply annotations

View File

@@ -8,7 +8,7 @@ import (
"strings"
"k8s.io/klog/v2"
system "undecided.project/monok8s/pkg/system"
system "example.com/monok8s/pkg/system"
)
type NetworkConfig struct {

View File

@@ -6,8 +6,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"undecided.project/monok8s/pkg/scheme"
"undecided.project/monok8s/pkg/templates"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
"example.com/monok8s/pkg/templates"
)
func RenderMonoKSConfig() (string, error) {
@@ -15,7 +15,7 @@ func RenderMonoKSConfig() (string, error) {
cfg := templates.DefaultMonoKSConfig(vals)
s := runtime.NewScheme()
if err := scheme.AddToScheme(s); err != nil {
if err := monov1alpha1.AddToScheme(s); err != nil {
return "", err
}
@@ -36,7 +36,7 @@ func RenderOSUpgrade() (string, error) {
cfg := templates.DefaultOSUpgrade(vals)
s := runtime.NewScheme()
if err := scheme.AddToScheme(s); err != nil {
if err := monov1alpha1.AddToScheme(s); err != nil {
return "", err
}

View File

@@ -1,27 +0,0 @@
package scheme
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
)
var (
GroupVersion = schema.GroupVersion{
Group: "monok8s.io",
Version: "v1alpha1",
}
)
func AddToScheme(s *runtime.Scheme) error {
s.AddKnownTypes(GroupVersion,
&types.MonoKSConfig{},
)
// Required for meta stuff
metav1.AddToGroupVersion(s, GroupVersion)
return nil
}

View File

@@ -3,23 +3,23 @@ package templates
import (
"strings"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
)
const DefaultNamespace = "kube-system"
func DefaultMonoKSConfig(v TemplateValues) types.MonoKSConfig {
return types.MonoKSConfig{
func DefaultMonoKSConfig(v TemplateValues) monov1alpha1.MonoKSConfig {
return monov1alpha1.MonoKSConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: "monok8s.io/v1alpha1",
APIVersion: monov1alpha1.APIVersion,
Kind: "MonoKSConfig",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: DefaultNamespace,
},
Spec: types.MonoKSConfigSpec{
Spec: monov1alpha1.MonoKSConfigSpec{
KubernetesVersion: v.KubernetesVersion,
NodeName: firstNonEmpty(v.NodeName, v.Hostname),
@@ -53,7 +53,7 @@ func DefaultMonoKSConfig(v TemplateValues) types.MonoKSConfig {
NodeLabels: copyStringMap(v.NodeLabels),
NodeAnnotations: copyStringMap(v.NodeAnnotations),
Network: types.NetworkSpec{
Network: monov1alpha1.NetworkSpec{
Hostname: firstNonEmpty(v.Hostname, v.NodeName),
ManagementIface: v.MgmtIface,
ManagementCIDR: v.MgmtAddress,
@@ -65,17 +65,17 @@ func DefaultMonoKSConfig(v TemplateValues) types.MonoKSConfig {
}
}
func DefaultOSUpgrade(v TemplateValues) types.OSUpgrade {
return types.OSUpgrade{
func DefaultOSUpgrade(v TemplateValues) monov1alpha1.OSUpgrade {
return monov1alpha1.OSUpgrade{
TypeMeta: metav1.TypeMeta{
APIVersion: "monok8s.io/v1alpha1",
APIVersion: monov1alpha1.APIVersion,
Kind: "OSUpgrade",
},
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Namespace: DefaultNamespace,
},
Spec: types.OSUpgradeSpec{
Spec: monov1alpha1.OSUpgradeSpec{
Version: v.KubernetesVersion,
ImageURL: "https://example.invalid/images/monok8s-v0.0.1.img.zst",
NodeSelector: &metav1.LabelSelector{

View File

@@ -4,7 +4,8 @@ import (
"os"
"strings"
buildinfo "undecided.project/monok8s/pkg/buildinfo"
monov1alpha1 "example.com/monok8s/pkg/apis/monok8s/v1alpha1"
buildinfo "example.com/monok8s/pkg/buildinfo"
)
type TemplateValues struct {
@@ -75,10 +76,10 @@ func defaultTemplateValues() TemplateValues {
SubjectAltNames: []string{"10.0.0.10", "localhost", "monok8s-master-1"},
NodeLabels: map[string]string{
"monok8s.io/label": "value",
monov1alpha1.Label: "value",
},
NodeAnnotations: map[string]string{
"monok8s.io/annotation": "value",
monov1alpha1.Annotation: "value",
},
}
}