Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Added deletion of namespace resources and optimized content #588

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions operator/pkg/uninstall/uninstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NamespacedResources() []schema.GroupVersionKind {
gvk.Secret.Kubernetes(),
gvk.ServiceAccount.Kubernetes(),
gvk.Job.Kubernetes(),
gvk.Namespace.Kubernetes(),
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"},
{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"},
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/art/art.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
//go:embed dubbo-ascii.txt
var dubboASCIIArt string

func dubboArt() string {
return dubboASCIIArt
}

func DubboColoredArt() string {
return color.New(color.FgHiBlue).Add(color.Bold).Sprint(dubboASCIIArt)
}
10 changes: 5 additions & 5 deletions pkg/art/dubbo-ascii.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
____ _ _
| _ \ _ _| |__ | |__ ___
| | | | | | | |_ \| |_ \ / _ \
| |_| | |_| | |_| | |_| | |_| |
|____/ \____|____/|____/ \___/
____ _ _
| _ \ _ _ | |__ | |__ ___
| | | | | | | | | |_ \ | |_ \ / _ \
| |_| | | |_| | | |_| | | |_| | | |_| |
|____/ \____| |____/ |____/ \___/
4 changes: 4 additions & 0 deletions pkg/config/schema/gvk/resources.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func ToGVR(g config.GroupVersionKind) (schema.GroupVersionResource, bool) {
return gvr.Service, true
case ServiceAccount:
return gvr.ServiceAccount, true
case Namespace:
return gvr.Namespace, true
case Job:
return gvr.Job, true
}
Expand All @@ -48,6 +50,8 @@ func FromGVR(g schema.GroupVersionResource) (config.GroupVersionKind, bool) {
switch g {
case gvr.CustomResourceDefinition:
return CustomResourceDefinition, true
case gvr.Namespace:
return Namespace, true
case gvr.Deployment:
return Deployment, true
case gvr.StatefulSet:
Expand Down
1 change: 1 addition & 0 deletions pkg/config/schema/gvr/resource.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var (
Deployment = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
StatefulSet = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}
Job = schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "jobs"}
Namespace = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "namespaces"}
Secret = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"}
Service = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "services"}
ServiceAccount = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "serviceaccounts"}
Expand Down
12 changes: 6 additions & 6 deletions pkg/kube/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ type clientConfig struct {
restConfig rest.Config
}

func NewClientConfigForRestConfig(restConfig *rest.Config) clientcmd.ClientConfig {
return &clientConfig{
restConfig: *restConfig,
}
}

func (c clientConfig) RawConfig() (api.Config, error) {
cfg := api.Config{
Kind: "Config",
Expand Down Expand Up @@ -39,9 +45,3 @@ func (c clientConfig) Namespace() (string, bool, error) {
func (c clientConfig) ConfigAccess() clientcmd.ConfigAccess {
return nil
}

func NewClientConfigForRestConfig(restConfig *rest.Config) clientcmd.ClientConfig {
return &clientConfig{
restConfig: *restConfig,
}
}
7 changes: 0 additions & 7 deletions pkg/kube/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ type clientFactory struct {
discoveryClient laziness.Laziness[discovery.CachedDiscoveryInterface]
}

type restClientGetter interface {
ToRestConfig() (*rest.Config, error)
ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
ToRestMapper() (meta.RESTMapper, error)
ToRawKubeConfigLoader() clientcmd.ClientConfig
}

func newClientFactory(clientConfig clientcmd.ClientConfig, diskCache bool) *clientFactory {
cf := &clientFactory{
clientConfig: clientConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ func NewSchemasBuilder() *SchemasBuilder {
return &SchemasBuilder{schemas: s}
}

func (b *SchemasBuilder) Build() Schemas {
s := b.schemas
b.schemas = Schemas{}
return s
}

func (b *SchemasBuilder) Add(s schema.Schema) error {
if _, found := b.schemas.byCollection[s.GroupVersionKind()]; found {
return fmt.Errorf("collection already exists: %v", s.GroupVersionKind())
Expand All @@ -54,3 +48,9 @@ func (b *SchemasBuilder) MustAdd(s schema.Schema) *SchemasBuilder {
}
return b
}

func (b *SchemasBuilder) Build() Schemas {
s := b.schemas
b.schemas = Schemas{}
return s
}
1 change: 1 addition & 0 deletions pkg/kube/informerfactory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (f *informerFactory) Shutdown() {

f.lock.Lock()
defer f.lock.Unlock()

f.shuttingDown = true
}

Expand Down
34 changes: 17 additions & 17 deletions pkg/kube/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ func BuildClientConfig(kubeconfig, context string) (*rest.Config, error) {
return c, nil
}

func SetRestDefaults(config *rest.Config) *rest.Config {
if config.GroupVersion == nil || config.GroupVersion.Empty() {
config.GroupVersion = &corev1.SchemeGroupVersion
}
if len(config.APIPath) == 0 {
if len(config.GroupVersion.Group) == 0 {
config.APIPath = "/api"
} else {
config.APIPath = "/apis"
}
}
if config.NegotiatedSerializer == nil {
config.NegotiatedSerializer = serializer.NewCodecFactory(nil).WithoutConversion()
}
return config
}

func BuildClientCmd(kubeconfig, context string, overrides ...func(configOverrides *clientcmd.ConfigOverrides)) clientcmd.ClientConfig {
if kubeconfig != "" {
info, err := os.Stat(kubeconfig)
Expand All @@ -63,3 +46,20 @@ func BuildClientCmd(kubeconfig, context string, overrides ...func(configOverride
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
}

func SetRestDefaults(config *rest.Config) *rest.Config {
if config.GroupVersion == nil || config.GroupVersion.Empty() {
config.GroupVersion = &corev1.SchemeGroupVersion
}
if len(config.APIPath) == 0 {
if len(config.GroupVersion.Group) == 0 {
config.APIPath = "/api"
} else {
config.APIPath = "/apis"
}
}
if config.NegotiatedSerializer == nil {
config.NegotiatedSerializer = serializer.NewCodecFactory(nil).WithoutConversion()
}
return config
}
Loading