Skip to content

Commit

Permalink
Merge pull request #35 from ganganxiaojiu/main
Browse files Browse the repository at this point in the history
delete pvc include olap
  • Loading branch information
nineinfra authored Jan 7, 2024
2 parents f91d40f + 1237398 commit 90e3ddf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ const (
DefaultSparkUIName = "spark-ui"
)
const (
FeaturesOlapKey = "olap"
DefaultDorisPortName = "query-port"
FeaturesOlapKey = "olap"
DefaultDorisPortName = "query-port"
DefaultOlapPVCLabelKey = "app.doris.ownerreference/name"
DefaultDorisBENameSuffix = "-doris-be"
DefaultDorisFENameSuffix = "-doris-fe"
)

var (
Expand Down
31 changes: 31 additions & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func constructPVCLabel(name string) string {
return DefaultPVCLabelKey + "=" + name
}

func constructOlabPVCLabel(name string) string {
return DefaultOlapPVCLabelKey + "=" + name + DefaultDorisBENameSuffix
}

func deleteNineInfraPVC(name string, namespace string) error {
if name == "" || namespace == "" {
return nil
Expand All @@ -93,6 +97,29 @@ func deleteNineInfraPVC(name string, namespace string) error {
return nil
}

func deleteOlapPVC(name string, namespace string) error {
if name == "" || namespace == "" {
return nil
}
path, _ := rootCmd.Flags().GetString(kubeconfig)
c, err := GetKubeClient(path)
if err != nil {
return err
}

olapPvcLabel := DefaultOlapPVCLabelKey + "=" + name + DefaultDorisBENameSuffix
err = c.CoreV1().PersistentVolumeClaims(namespace).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: olapPvcLabel})
if err != nil {
return err
}
olapPvcLabel = DefaultOlapPVCLabelKey + "=" + name + DefaultDorisFENameSuffix
err = c.CoreV1().PersistentVolumeClaims(namespace).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: olapPvcLabel})
if err != nil {
return err
}
return nil
}

func (d *deleteCmd) run(args []string) error {
path, _ := rootCmd.Flags().GetString(kubeconfig)
nc, err := GetNineInfraClient(path)
Expand All @@ -112,6 +139,10 @@ func (d *deleteCmd) run(args []string) error {
if err != nil {
return err
}
err = deleteOlapPVC(d.deleteOpts.Name+DefaultNineSuffix, d.deleteOpts.NS)
if err != nil {
return err
}
} else {
fmt.Println("All PVCs used by Nine will not be deleted")
}
Expand Down

0 comments on commit 90e3ddf

Please sign in to comment.