Skip to content

Commit

Permalink
Only delete non-local APIServices
Browse files Browse the repository at this point in the history
Co-authored-by: zanetworker <adel.zalok.89@gmail.com>
  • Loading branch information
rfranzke and zanetworker committed Sep 27, 2018
1 parent 9767167 commit e930156
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
5 changes: 5 additions & 0 deletions pkg/client/kubernetes/base/apiservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (c *Client) ListAPIServices(opts metav1.ListOptions) (*apiregistrationv1.AP
return c.apiServices().List(opts)
}

// DeleteAPIService will gracefully delete an APIService with the given <name>.
func (c *Client) DeleteAPIService(name string) error {
return c.apiServices().Delete(name, &defaultDeleteOptions)
}

// DeleteAPIServiceForcefully will forcefully delete an APIService with the given <name>.
func (c *Client) DeleteAPIServiceForcefully(name string) error {
apiService, err := c.apiServices().Get(name, metav1.GetOptions{})
Expand Down
1 change: 0 additions & 1 deletion pkg/client/kubernetes/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func NewForConfig(config *rest.Config) (*Client, error) {
restClient: clientset.Discovery().RESTClient(),

resourceAPIGroups: map[string][]string{
APIServices: {"apis", "apiregistration.k8s.io", "v1beta1"},
CronJobs: {"apis", "batch", "v1beta1"},
CustomResourceDefinitions: {"apis", "apiextensions.k8s.io", "v1beta1"},
DaemonSets: {"apis", "apps", "v1"},
Expand Down
3 changes: 0 additions & 3 deletions pkg/client/kubernetes/base/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ const (
// CustomResourceDefinitions is a constant for a Kubernetes resource with the same name.
CustomResourceDefinitions = "customresourcedefinitions"

// APIServices is a constant for a Kubernetes resource with the same name.
APIServices = "apiservices"

// DaemonSets is a constant for a Kubernetes resource with the same name.
DaemonSets = "daemonsets"

Expand Down
1 change: 1 addition & 0 deletions pkg/client/kubernetes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type Client interface {

// APIServices
ListAPIServices(metav1.ListOptions) (*apiregistrationv1.APIServiceList, error)
DeleteAPIService(name string) error
DeleteAPIServiceForcefully(name string) error

// Arbitrary manifests
Expand Down
1 change: 0 additions & 1 deletion pkg/client/kubernetes/v110/v110.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func NewForConfig(config *rest.Config) (*Client, error) {

// NewFrom creates a new client from the given kubernetesv19.Client.
func NewFrom(v19Client *kubernetesv19.Client) *Client {
v19Client.SetResourceAPIGroup(kubernetesbase.APIServices, []string{"apis", "apiregistration.k8s.io", "v1"})
return &Client{Client: v19Client}
}

Expand Down
46 changes: 24 additions & 22 deletions pkg/operation/botanist/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ import (
)

var (
customResourceDefinitionExceptions = map[string]bool{
"felixconfigurations.crd.projectcalico.org": true,
"bgppeers.crd.projectcalico.org": true,
"bgpconfigurations.crd.projectcalico.org": true,
"ippools.crd.projectcalico.org": true,
"clusterinformations.crd.projectcalico.org": true,
"globalnetworkpolicies.crd.projectcalico.org": true,
"globalnetworksets.crd.projectcalico.org": true,
"networkpolicies.crd.projectcalico.org": true,
"hostendpoints.crd.projectcalico.org": true,
}

exceptions = map[string]map[string]bool{
kubernetesbase.CustomResourceDefinitions: customResourceDefinitionExceptions,
kubernetesbase.CustomResourceDefinitions: map[string]bool{
"felixconfigurations.crd.projectcalico.org": true,
"bgppeers.crd.projectcalico.org": true,
"bgpconfigurations.crd.projectcalico.org": true,
"ippools.crd.projectcalico.org": true,
"clusterinformations.crd.projectcalico.org": true,
"globalnetworkpolicies.crd.projectcalico.org": true,
"globalnetworksets.crd.projectcalico.org": true,
"networkpolicies.crd.projectcalico.org": true,
"hostendpoints.crd.projectcalico.org": true,
},
kubernetesbase.DaemonSets: {
fmt.Sprintf("%s/calico-node", metav1.NamespaceSystem): true,
fmt.Sprintf("%s/kube-proxy", metav1.NamespaceSystem): true,
Expand Down Expand Up @@ -117,7 +115,7 @@ func (b *Botanist) ForceDeleteCustomResourceDefinitions() error {

var result error
for _, crd := range crdList.Items {
if omit, ok := customResourceDefinitionExceptions[crd.Name]; !ok || !omit {
if omit, ok := exceptions[kubernetesbase.CustomResourceDefinitions][crd.Name]; !ok || !omit {
if err := b.K8sShootClient.DeleteCRDForcefully(crd.Name); err != nil && !apierrors.IsNotFound(err) {
result = multierror.Append(result, err)
}
Expand All @@ -129,16 +127,20 @@ func (b *Botanist) ForceDeleteCustomResourceDefinitions() error {
// CleanupCustomAPIServices deletes all the custom API services in the Kubernetes cluster.
// It will wait until all resources have been cleaned up.
func (b *Botanist) CleanupCustomAPIServices() error {
var (
apiGroups = b.K8sShootClient.GetResourceAPIGroups()
resource = kubernetesbase.APIServices
apiServiceGroupPath = apiGroups[resource]
)

if err := b.K8sShootClient.CleanupAPIGroupResources(exceptions, resource, apiServiceGroupPath); err != nil {
apiServiceList, err := b.K8sShootClient.ListAPIServices(metav1.ListOptions{})
if err != nil {
return err
}
return b.waitForAPIGroupCleanedUp(apiServiceGroupPath, resource)

var result error
for _, apiService := range apiServiceList.Items {
if apiService.Spec.Service != nil {
if err := b.K8sShootClient.DeleteAPIService(apiService.Name); err != nil && !apierrors.IsNotFound(err) {
result = multierror.Append(result, err)
}
}
}
return result
}

// ForceDeleteCustomAPIServices forcefully deletes all custom API services,
Expand Down

0 comments on commit e930156

Please sign in to comment.