Skip to content

Commit

Permalink
apply prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidya2606 committed Oct 2, 2024
1 parent b49aa19 commit 25fc568
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export async function run() {
.map((manifest) => manifest.trim()) // remove surrounding whitespace
.filter((manifest) => manifest.length > 0) // remove any blanks

const fullManifestFilePaths = await getFilesFromDirectoriesAndURLs(
manifestFilePaths
)
const fullManifestFilePaths =
await getFilesFromDirectoriesAndURLs(manifestFilePaths)
const kubectlPath = await getKubectlPath()
const namespace = core.getInput('namespace') || 'default'
const isPrivateCluster =
Expand Down
5 changes: 2 additions & 3 deletions src/strategyHelpers/blueGreen/smiBlueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ export async function createTrafficSplitObject(
): Promise<TrafficSplitObject> {
// cache traffic split api version
if (!trafficSplitAPIVersion)
trafficSplitAPIVersion = await kubectlUtils.getTrafficSplitAPIVersion(
kubectl
)
trafficSplitAPIVersion =
await kubectlUtils.getTrafficSplitAPIVersion(kubectl)

// retrieve annotations for TS object
const annotations = inputAnnotations
Expand Down
20 changes: 13 additions & 7 deletions src/strategyHelpers/canary/podCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ export async function deployPodCanary(
const fileContents = fs.readFileSync(filePath, 'utf8')
const parsedYaml = yaml.loadAll(fileContents)
for (const inputObject of parsedYaml) {
if (inputObject && typeof inputObject === 'object' && 'metadata' in inputObject && 'kind' in inputObject) {
const name = (inputObject as any).metadata?.name;
const kind = (inputObject as any).kind;
if (
inputObject &&
typeof inputObject === 'object' &&
'metadata' in inputObject &&
'kind' in inputObject
) {
const name = (inputObject as any).metadata?.name
const kind = (inputObject as any).kind

if (!onlyDeployStable && isDeploymentEntity(kind)) {
core.debug('Calculating replica count for canary')
Expand All @@ -36,10 +41,11 @@ export async function deployPodCanary(
)
core.debug('Replica count is ' + canaryReplicaCount)

const newCanaryObject = canaryDeploymentHelper.getNewCanaryResource(
inputObject,
canaryReplicaCount
)
const newCanaryObject =
canaryDeploymentHelper.getNewCanaryResource(
inputObject,
canaryReplicaCount
)
newObjectsList.push(newCanaryObject)

// if there's already a stable object, deploy baseline as well
Expand Down
15 changes: 8 additions & 7 deletions src/strategyHelpers/canary/smiCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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'
import {K8sObject} from '../../types/k8sObject'

const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout'
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit'
Expand All @@ -38,7 +38,9 @@ export async function deploySMICanary(
const newObjectsList = []
for await (const filePath of filePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const inputObjects: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]
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 @@ -113,7 +115,7 @@ async function createCanaryService(

for (const filePath of filePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[];
const parsedYaml: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]

for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
Expand Down Expand Up @@ -227,7 +229,7 @@ async function adjustTraffic(
const trafficSplitManifests = []
for (const filePath of manifestFilePaths) {
const fileContents = fs.readFileSync(filePath).toString()
const parsedYaml: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[];
const parsedYaml: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]

for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
Expand Down Expand Up @@ -324,9 +326,8 @@ async function getTrafficSplitObject(
): Promise<string> {
// cached version
if (!trafficSplitAPIVersion) {
trafficSplitAPIVersion = await kubectlUtils.getTrafficSplitAPIVersion(
kubectl
)
trafficSplitAPIVersion =
await kubectlUtils.getTrafficSplitAPIVersion(kubectl)
}

return JSON.stringify({
Expand Down
3 changes: 1 addition & 2 deletions src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function appendStableVersionLabelToResource(files: string[]): string[] {
const fileContents = fs.readFileSync(filePath).toString()

yaml.loadAll(fileContents, function (inputObject) {
const kind = (inputObject as { kind: string }).kind;
const kind = (inputObject as {kind: string}).kind

if (isDeploymentEntity(kind)) {
const updatedObject =
Expand All @@ -131,7 +131,6 @@ function appendStableVersionLabelToResource(files: string[]): string[] {
return manifestFiles
}


export async function checkManifestStability(
kubectl: Kubectl,
resources: Resource[]
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/fileUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ 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';
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: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[];
const inputObjects: K8sObject[] = yaml.loadAll(
fileContents
) as K8sObject[]
expect(inputObjects).toHaveLength(1)

for (const obj of inputObjects) {
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,7 +20,7 @@ import {
setImagePullSecrets
} from './manifestPullSecretUtils'
import {Resource} from '../types/kubectl'
import { K8sObject } from '../types/k8sObject';
import {K8sObject} from '../types/k8sObject'

export function updateManifestFiles(manifestFilePaths: string[]) {
if (manifestFilePaths?.length === 0) {
Expand Down Expand Up @@ -276,7 +276,9 @@ export function getResources(
const resources: Resource[] = []
filePaths.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()
const inputObjects: K8sObject[] = yaml.loadAll(fileContents) as K8sObject[]
const inputObjects: K8sObject[] = yaml.loadAll(
fileContents
) as K8sObject[]
inputObjects.forEach((inputObject) => {
const inputObjectKind = inputObject?.kind || ''
if (
Expand Down

0 comments on commit 25fc568

Please sign in to comment.