async function annotateResources()

in src/strategyHelpers/deploymentHelper.ts [190:274]


async function annotateResources(
   files: string[],
   kubectl: Kubectl,
   resourceTypes: Resource[],
   annotationKey: string,
   workflowFilePath: string,
   deploymentConfig: DeploymentConfig
) {
   const annotateResults: ExecOutput[] = []
   const namespace = core.getInput('namespace') || 'default'
   const lastSuccessSha = await getLastSuccessfulRunSha(
      kubectl,
      namespace,
      annotationKey
   )

   if (core.isDebug()) {
      try {
         core.debug(`files getting annotated are ${JSON.stringify(files)}`)
         for (const filePath of files) {
            core.debug('printing objects getting annotated...')
            const fileContents = fs.readFileSync(filePath).toString()
            const inputObjects = yaml.loadAll(fileContents)
            for (const inputObject of inputObjects) {
               core.debug(`object: ${JSON.stringify(inputObject)}`)
            }
         }
      } catch (error) {
         core.error(`Failed to load and parse files: ${error.message}`)
         throw error
      }
   }

   const annotationKeyValStr = `${annotationKey}=${getWorkflowAnnotations(
      lastSuccessSha,
      workflowFilePath,
      deploymentConfig
   )}`

   const annotateNamespace = !(
      core.getInput('annotate-namespace').toLowerCase() === 'false'
   )
   if (annotateNamespace) {
      annotateResults.push(
         await kubectl.annotate(
            'namespace',
            namespace,
            annotationKeyValStr,
            namespace
         )
      )
   }

   for (const file of files) {
      try {
         const annotateResult = await kubectl.annotateFiles(
            file,
            annotationKeyValStr,
            namespace
         )
         annotateResults.push(annotateResult)
      } catch (e) {
         core.warning(`failed to annotate resource: ${e}`)
      }
   }

   for (const resource of resourceTypes) {
      if (
         resource.type.toLowerCase() !==
         models.KubernetesWorkload.POD.toLowerCase()
      ) {
         ;(
            await annotateChildPods(
               kubectl,
               resource.type,
               resource.name,
               resource.namespace,
               annotationKeyValStr
            )
         ).forEach((execResult) => annotateResults.push(execResult))
      }
   }

   checkForErrors(annotateResults, true)
}