Skip to content

Commit

Permalink
code changes to use yaml.loadAll and upgrade of octokit version
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidya2606 committed Oct 2, 2024
1 parent 7c02f0d commit fe8a8e0
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 151 deletions.
348 changes: 211 additions & 137 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@actions/exec": "^1.0.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "2.0.1",
"@octokit/core": "^6.1.2",
"@octokit/plugin-retry": "^7.1.2",
"@octokit/core": "^3.5.1",
"@octokit/plugin-retry": "^3.0.9",
"@types/minipass": "^3.3.5",
"js-yaml": "4.1.0",
"minimist": "^1.2.8"
Expand Down
2 changes: 1 addition & 1 deletion src/strategyHelpers/blueGreen/blueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getManifestObjects(filePaths: string[]): BlueGreenManifests {
// organized before we can check if services are “routed” or not.
filePaths.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()
yaml.safeLoadAll(fileContents, (inputObject) => {
yaml.loadAll(fileContents, (inputObject: any) => {
if (!!inputObject) {
const kind = inputObject.kind

Expand Down
2 changes: 1 addition & 1 deletion src/strategyHelpers/canary/canaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async function cleanUpCanary(
for (const filePath of files) {
const fileContents = fs.readFileSync(filePath).toString()

const parsedYaml = yaml.safeLoadAll(fileContents)
const parsedYaml: any[] = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
Expand Down
2 changes: 1 addition & 1 deletion src/strategyHelpers/canary/podCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function deployPodCanary(

for (const filePath of filePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml = yaml.safeLoadAll(fileContents)
const parsedYaml = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
Expand Down
7 changes: 4 additions & 3 deletions src/strategyHelpers/canary/smiCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {isDeploymentEntity, isServiceEntity} from '../../types/kubernetesTypes'
import {checkForErrors} from '../../utilities/kubectlUtils'
import {inputAnnotations} from '../../inputUtils'
import {DeployResult} from '../../types/deployResult'
import { K8sObject } from '../../types/k8sObject'

const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout'
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit'
Expand All @@ -37,7 +38,7 @@ export async function deploySMICanary(
const newObjectsList = []
for await (const filePath of filePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const inputObjects = yaml.safeLoadAll(fileContents)
const inputObjects: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]
for (const inputObject of inputObjects) {
const name = inputObject.metadata.name
const kind = inputObject.kind
Expand Down Expand Up @@ -112,7 +113,7 @@ async function createCanaryService(

for (const filePath of filePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml = yaml.safeLoadAll(fileContents)
const parsedYaml = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
Expand Down Expand Up @@ -225,7 +226,7 @@ async function adjustTraffic(
const trafficSplitManifests = []
for (const filePath of manifestFilePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml = yaml.safeLoadAll(fileContents)
const parsedYaml = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
Expand Down
4 changes: 2 additions & 2 deletions src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function appendStableVersionLabelToResource(files: string[]): string[] {
files.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()

yaml.safeLoadAll(fileContents, function (inputObject) {
yaml.loadAll(fileContents, function (inputObject) {
const {kind} = inputObject

if (isDeploymentEntity(kind)) {
Expand Down Expand Up @@ -197,7 +197,7 @@ async function annotateResources(
for (const filePath of files) {
core.debug('printing objects getting annotated...')
const fileContents = fs.readFileSync(filePath).toString()
const inputObjects = yaml.safeLoadAll(fileContents)
const inputObjects = yaml.loadAll(fileContents)
for (const inputObject of inputObjects) {
core.debug(`object: ${JSON.stringify(inputObject)}`)
}
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/fileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import * as fileUtils from './fileUtils'
import * as yaml from 'js-yaml'
import * as fs from 'fs'
import * as path from 'path'
import { K8sObject } from '../types/k8sObject';

const sampleYamlUrl =
'https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml'
describe('File utils', () => {
test('correctly parses a yaml file from a URL', async () => {
const tempFile = await fileUtils.writeYamlFromURLToFile(sampleYamlUrl, 0)
const fileContents = fs.readFileSync(tempFile).toString()
const inputObjects = yaml.safeLoadAll(fileContents)
const inputObjects: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]; // Type assertion here

expect(inputObjects).toHaveLength(1)

for (const obj of inputObjects) {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function verifyYaml(filepath: string, url: string): Errorable<K8sObject[]> {
const fileContents = fs.readFileSync(filepath).toString()
let inputObjects
try {
inputObjects = yaml.safeLoadAll(fileContents)
inputObjects = yaml.loadAll(fileContents)
} catch (e) {
return {
succeeded: false,
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/manifestUpdateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
setImagePullSecrets
} from './manifestPullSecretUtils'
import {Resource} from '../types/kubectl'
import { K8sObject } from '../types/k8sObject';

export function updateManifestFiles(manifestFilePaths: string[]) {
if (manifestFilePaths?.length === 0) {
Expand Down Expand Up @@ -275,7 +276,8 @@ export function getResources(
const resources: Resource[] = []
filePaths.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()
yaml.safeLoadAll(fileContents, (inputObject) => {
const inputObjects: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]
inputObjects.forEach((inputObject) => {
const inputObjectKind = inputObject?.kind || ''
if (
filterResourceTypes.filter(
Expand Down Expand Up @@ -303,7 +305,7 @@ function updateImagePullSecretsInManifestFiles(
const newObjectsList = []
filePaths.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()
yaml.safeLoadAll(fileContents, (inputObject: any) => {
yaml.loadAll(fileContents, (inputObject: any) => {
if (inputObject?.kind) {
const {kind} = inputObject
if (isWorkloadEntity(kind)) {
Expand Down

0 comments on commit fe8a8e0

Please sign in to comment.