#!/bin/sh # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. echo "Removing empty directories from etcd..." proc cleanup_empty_dirs { if test $[$(ETCDCTL) ls $1] { for SUBDIR in [$[$(ETCDCTL) ls -p $1 | grep "/$]] { cleanup_empty_dirs $(SUBDIR) } } else { echo "Removing empty key $1 ..." $(ETCDCTL) rmdir $1 } } while true { echo "Starting cleanup..." cleanup_empty_dirs "/registry" echo "Done with cleanup." sleep $(SLEEP_SECOND) } (CommandList children: [ (C {(echo)} {(DQ ("Removing empty directories from etcd..."))}) (FuncDef name: cleanup_empty_dirs body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(${ VSub_Name ETCDCTL)} {(ls)} {($ VSub_Number "$1")}) ] ) left_token: spids: [64 72] ) ) } {(Lit_Other "]")} ) terminator: ) ] action: [ (ForEach iter_name: SUBDIR iter_words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(${ VSub_Name ETCDCTL)} {(ls)} {(-p)} {($ VSub_Number "$1")}) (C {(grep)} {(DQ (/) (Lit_Other "$"))}) ] negated: False ) ] ) left_token: spids: [87 106] ) } ] do_arg_iter: False body: (DoGroup children: [(C {(cleanup_empty_dirs)} {(${ VSub_Name SUBDIR)})] spids: [109 119] ) spids: [86 -1] ) ] spids: [-1 78] ) ] else_action: [ (C {(echo)} {(DQ ("Removing empty key ") ($ VSub_Number "$1") (" ..."))}) (C {(${ VSub_Name ETCDCTL)} {(rmdir)} {($ VSub_Number "$1")}) ] spids: [122 143] ) ] spids: [56] ) spids: [51 55] ) (While cond: [(C {(true)})] body: (DoGroup children: [ (C {(echo)} {(DQ ("Starting cleanup..."))}) (C {(cleanup_empty_dirs)} {(DQ (/registry))}) (C {(echo)} {(DQ ("Done with cleanup."))}) (C {(sleep)} {(${ VSub_Name SLEEP_SECOND)}) ] spids: [152 182] ) ) ] )