diff --git a/chaosmeta-inject-operator/pkg/scopehandler/pod/handler.go b/chaosmeta-inject-operator/pkg/scopehandler/pod/handler.go index 86bd280..274b6ff 100644 --- a/chaosmeta-inject-operator/pkg/scopehandler/pod/handler.go +++ b/chaosmeta-inject-operator/pkg/scopehandler/pod/handler.go @@ -137,8 +137,9 @@ func getPodObjectList(ctx context.Context, selectorUnit v1alpha1.SelectorUnit) ( var result = make([]model.AtomicObject, 0) for _, pod := range podList { - for _, subObject := range pod.GetSubObjects() { - result = append(result, &subObject) + subObjects := pod.GetSubObjects() + for i, _ := range subObjects { + result = append(result, &subObjects[i]) } } diff --git a/chaosmeta-inject-operator/pkg/selector/selector.go b/chaosmeta-inject-operator/pkg/selector/selector.go index 81b9429..f17b314 100644 --- a/chaosmeta-inject-operator/pkg/selector/selector.go +++ b/chaosmeta-inject-operator/pkg/selector/selector.go @@ -29,8 +29,9 @@ import ( ) const ( - HostIPKey = ".status.hostIP" - PhaseKey = ".status.phase" + HostIPKey = ".status.hostIP" + PhaseKey = ".status.phase" + containerRegFmt = "^(%s)$" ) var ( @@ -227,7 +228,6 @@ func GetTargetContainers(containerReg string, status []corev1.ContainerStatus) ( return } containerReg = strings.ReplaceAll(containerReg, ",", "|") - reg := regexp.MustCompile(containerReg) containers = []model.ContainerInfo{} var targetContainerInfo corev1.ContainerStatus // no container setting equals to firstcontainer setting @@ -239,6 +239,7 @@ func GetTargetContainers(containerReg string, status []corev1.ContainerStatus) ( } containers = append(containers, *info) } else { + reg := regexp.MustCompile(fmt.Sprintf(containerRegFmt, containerReg)) for _, containerStatus := range status { if reg.MatchString(containerStatus.Name) { info, err := getContainerInfo(containerStatus)