export async function annotateChildPods()

in src/utilities/kubectlUtils.ts [59:102]


export async function annotateChildPods(
   kubectl: Kubectl,
   resourceType: string,
   resourceName: string,
   namespace: string | undefined,
   annotationKeyValStr: string
): Promise<ExecOutput[]> {
   let owner = resourceName
   if (resourceType.toLowerCase().indexOf('deployment') > -1) {
      owner = await kubectl.getNewReplicaSet(resourceName, namespace)
   }

   const commandExecutionResults = []

   let allPods
   try {
      allPods = JSON.parse((await kubectl.getAllPods()).stdout)
   } catch (e) {
      core.debug(`Unable to parse pods: ${e}`)
   }

   if (allPods?.items && allPods.items?.length > 0) {
      allPods.items.forEach((pod) => {
         const owners = pod?.metadata?.ownerReferences
         if (owners) {
            for (const ownerRef of owners) {
               if (ownerRef.name === owner) {
                  commandExecutionResults.push(
                     kubectl.annotate(
                        'pod',
                        pod.metadata.name,
                        annotationKeyValStr,
                        namespace
                     )
                  )
                  break
               }
            }
         }
      })
   }

   return await Promise.all(commandExecutionResults)
}