Skip to content

Commit

Permalink
v4 new release (#274)
Browse files Browse the repository at this point in the history
* Add missing API switch for GHES (#200)

* Vidya reddy/prettier code (#203)

* switch none deployment strategy to basic (#204)

* switch none deployment strategy to basic

* update readme

* update deployment strategy fallthrough logic

* comment fixed

* add disclaimer for basic strategy only supporting deploy action

* Hari/beautify logs (#206)

* Logging changes for deploy

* Logging Changes with group

* format check changes

* Add ncc build to build script (#208)

Co-authored-by: Vidya Reddy <[email protected]>

* Logging Changes for Promote, Reject actions (#207)

* add clean function (#211)

* Added Traffic split annotations (#215)

* Added Traffic split annotations

* traffic split - blueGreen deployment

* traffic split - canary deployment

* Traffic split annotations - canary deployment

* updated Readme and action.yml

* Traffic split - canary deployment

* clean code

* Clean code

* Clean code

* Create annotation object

* Updated Readme and action.yml

* Spelling correction

Co-authored-by: Vidya Reddy <[email protected]>

* Swap annotation key to actions.github.com prefix (#216)

* Private Cluster functionality (#214)

* Fixed Blue/Green Strategy Ingress Route-Method Glitch  (#217)

* Added some tests, not sure what else to try but gonna think of more examples

* forgot some files

* reverted package-lock.json

* Added empty dir test

* Cleaned up some extra spaces

* Add node modules and compiled JavaScript from main

* forgot to actually include functionality

* removed unnecessary files

* Update .gitignore

* Update .gitignore

* Update .gitignore

* thx david

* renamed searchFilesRec

* integrations test fix

* added examples to README

* added note about depth

* added additional note

* removed ticks

* changed version string

* removed conflict on readme

* Added tests for bluegreen helper and resolved issue with ingress not being read correctly, still have to figure out why new services aren't showing up

* resolved services name issue

* looks functional, beginning refactor now

* refactored deploy methods for type error

* Removed refactor comments

* prettier

* implemented Oliver's feedback

* prettier

* added optional chaining operator

* removed refactor comment

Co-authored-by: Jaiveer Katariya <[email protected]>
Co-authored-by: Oliver King <[email protected]>
Co-authored-by: Jaiveer Katariya <[email protected]>

* Blue/Green Refactor (#229)

* fresh new branch

* Added coverage to gitignore

Signed-off-by: Jaiveer Katariya <[email protected]>

* reverted package-lock.json

Signed-off-by: Jaiveer Katariya <[email protected]>
Co-authored-by: Jaiveer Katariya <[email protected]>

* consider slashes while cleaning labels (#231)

fix prettier format check errors

* Fix README.md typo (#235)

* Bump @actions/core from 1.9.0 to 1.9.1 (#233)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add permissions to README.md (#236)

* Add permissions to README.md

* remove space

* prettier

* remove extra changes

* fix spacing

* Add the bug report and feature request form (#237)

* Added the bug report and feature request form

* updated the url

* Fix issue form (#238)

* Fix description about baseline-and-canary-replicas (#241)

* Resolved issue with Canary deploy (#247)

* Added support message (#249)

* Deploy with Manifests from URLs (#251)

* added functionality, need to add/modify existing tests

* added tests

* updated readme

* prettier

* Fix private cluster kubectl exit code bug (#252)

* add private cluster exitCode check

* add proper output

* Added Integration Tests, Resolved Bugs With Annotations (#255)

* First commit - made manifests for test deployments, made manifests for i tests for other deployment strategies

* broke down blue/green

* added latest tags to test manifests for new tags

* remade tester

* ready to test bgi

* using all but first index of argv

* careless error with dicts

* added test to namespace

* realized i was silencing error

* indexing containers

* keyerror

* logging bc python errors are weird

* expected still string

* parsed args behaving weirdly

* test seems to be working now, applying changes to other YAMLs now

* blue/green ready to test

* oops

* oops

* Added additional labels to check

* hyphen

* Added our annotations

* lol

* added our labels to services too

* nonetype issue'

* nonetype issue'

* narrowing down parameter

* fixed annotations issue with promote

* adding debhug statement to figure out why services aren't getting annotations

* this should fix annotations issue for service

* not sure why this wasn't caught by intellisense

* should be fixed with removing comma but adding logs in case

* added linkerd install

* verification

* upgraded kubernetes version

* removing crds

* proxy option

* Added smi extension

* logging service

* smi svcs also getting labeled now

* matching ts type

* not sure where stable service is going

* remaining svc and deployment should match

* keeping stable service and ts object

* updated tests to reflect keeping ts object

* no green svc after promote

* duh

* lol

* canary work

* canary test ready

* logging for ing, filename for canary

* changed ingress svc key and returning svc files from smi canary deployment

* ts name

* forgot about baseline in first deploy

* *

* *

* smi canary should annotate, fixed cleanup

* typescript issue plus percentage

* forgot to type extra method

* removed cleaned up objects from annotate list

* logging because services aren't getting removed

* moving to try/catch strategy of annotation since deletion can fail silently/with warnings

* moved label to individual

* removing canary service check after promote

* pod ready for testing

* set weights to 1000

* selectors

* *

* percentage

* *

* typing

* mixed up pod and smi

* fixed tests

* prettier

* forgot to remove canary

* cleanup

* Added oliver's feedback + more cleanup

* ncc as dev dependency

* npx

* going back to global ncc install bc npm is being weird

* prettier

* removed unnecessary post step

* new commit with all changes (#258)

* Fixing Ubuntu Runner Issue (#259)

* changed ubuntu runner

* changed minikube action

* Version formatting

* nonedriveR

* update kube version

* installing conntrack'

* updated other actions

* update bg ingress api version

* prettify

* updated ingress backend for new api version

* Added path type

* prettify

* Add skip tls flag (#260)

* bump @actions/core (#262)

* fixed files to file (#265)

* Update README.md to v4 (#263)

* Fixing Regex Issue + Adding Check for Failures Connecting to Github Repos (#271)

* changed ubuntu runner

* changed minikube action

* Version formatting

* nonedriveR

* update kube version

* installing conntrack'

* updated other actions

* update bg ingress api version

* prettify

* updated ingress backend for new api version

* Added path type

* prettify

* added logging

* added try catch logic to prevent future failures if annotations fail since failing annotations shouldn't affect users

* added nullcheck

* Added fallback filename if workflow fails to get github filepath due to runner issues

* cleanup

* added oliver's feedback + unit test demonstrating regex glitch and fix

* no longer using blank string for failed regex

* abstract methods to avoid drift (#273)

* Add node modules and compiled JavaScript from main

Signed-off-by: Jaiveer Katariya <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: nv35 <[email protected]>
Co-authored-by: Vidya <[email protected]>
Co-authored-by: David Gamero <[email protected]>
Co-authored-by: Hariharan Subramanian <[email protected]>
Co-authored-by: Vidya Reddy <[email protected]>
Co-authored-by: Oliver King <[email protected]>
Co-authored-by: Marcus-Hines <[email protected]>
Co-authored-by: Jaiveer Katariya <[email protected]>
Co-authored-by: Jaiveer Katariya <[email protected]>
Co-authored-by: Jaiveer Katariya <[email protected]>
Co-authored-by: Alexander Bartsch <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kenta Nakase <[email protected]>
Co-authored-by: Asa Gayle <[email protected]>
  • Loading branch information
15 people authored Dec 20, 2022
1 parent c7b3487 commit 5782616
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
37 changes: 28 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22017,12 +22017,20 @@ function checkManifestStability(kubectl, resources) {
exports.checkManifestStability = checkManifestStability;
function annotateAndLabelResources(files, kubectl, resourceTypes, allPods) {
return __awaiter(this, void 0, void 0, function* () {
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation';
const githubToken = core.getInput('token');
const workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
let workflowFilePath;
try {
workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
}
catch (ex) {
core.warning(`Failed to extract workflow file name: ${ex}`);
workflowFilePath = defaultWorkflowFileName;
}
const deploymentConfig = yield dockerUtils_1.getDeploymentConfig();
const annotationKeyLabel = workflowAnnotationUtils_1.getWorkflowAnnotationKeyLabel();
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig);
yield labelResources(files, kubectl, annotationKeyLabel);
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig).catch((err) => core.warning(`Failed to annotate resources: ${err} `));
yield labelResources(files, kubectl, annotationKeyLabel).catch((err) => core.warning(`Failed to label resources: ${err}`));
});
}
exports.annotateAndLabelResources = annotateAndLabelResources;
Expand Down Expand Up @@ -22360,13 +22368,17 @@ class Kubectl {
let newReplicaSet = '';
if (result === null || result === void 0 ? void 0 : result.stdout) {
const stdout = result.stdout.split('\n');
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout));
stdout.forEach((line) => {
const newreplicaset = 'newreplicaset';
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
core.debug(`found string of interest for replicaset, line is ${line}`);
core.debug(`substring is ${line.substring(newreplicaset.length).trim()}`);
newReplicaSet = line
.substring(newreplicaset.length)
.trim()
.split(' ')[0];
}
});
}
return newReplicaSet;
Expand Down Expand Up @@ -23803,8 +23815,9 @@ exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = void 0;
exports.removeInvalidLabelCharacters = exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = exports.VALID_LABEL_REGEX = void 0;
const ANNOTATION_PREFIX = 'actions.github.com';
exports.VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
function getWorkflowAnnotations(lastSuccessRunSha, workflowFilePath, deploymentConfig) {
const annotationObject = {
run: process.env.GITHUB_RUN_ID,
Expand Down Expand Up @@ -23836,14 +23849,20 @@ exports.getWorkflowAnnotationKeyLabel = getWorkflowAnnotationKeyLabel;
* @returns cleaned label
*/
function cleanLabel(label) {
let removedInvalidChars = label
let removedInvalidChars = removeInvalidLabelCharacters(label);
const regexResult = exports.VALID_LABEL_REGEX.exec(removedInvalidChars) || [
'github-workflow-file'
];
return regexResult[0];
}
exports.cleanLabel = cleanLabel;
function removeInvalidLabelCharacters(label) {
return label
.replace(/\s/gi, '_')
.replace(/[\/\\\|]/gi, '-')
.replace(/[^-A-Za-z0-9_.]/gi, '');
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
return regex.exec(removedInvalidChars)[0] || '';
}
exports.cleanLabel = cleanLabel;
exports.removeInvalidLabelCharacters = removeInvalidLabelCharacters;


/***/ }),
Expand Down
14 changes: 12 additions & 2 deletions src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,15 @@ export async function annotateAndLabelResources(
resourceTypes: Resource[],
allPods: any
) {
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation'
const githubToken = core.getInput('token')
const workflowFilePath = await getWorkflowFilePath(githubToken)
let workflowFilePath
try {
workflowFilePath = await getWorkflowFilePath(githubToken)
} catch (ex) {
core.warning(`Failed to extract workflow file name: ${ex}`)
workflowFilePath = defaultWorkflowFileName
}

const deploymentConfig = await getDeploymentConfig()
const annotationKeyLabel = getWorkflowAnnotationKeyLabel()
Expand All @@ -164,8 +171,11 @@ export async function annotateAndLabelResources(
annotationKeyLabel,
workflowFilePath,
deploymentConfig
).catch((err) => core.warning(`Failed to annotate resources: ${err} `))

await labelResources(files, kubectl, annotationKeyLabel).catch((err) =>
core.warning(`Failed to label resources: ${err}`)
)
await labelResources(files, kubectl, annotationKeyLabel)
}

async function annotateResources(
Expand Down
10 changes: 9 additions & 1 deletion src/types/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ export class Kubectl {
let newReplicaSet = ''
if (result?.stdout) {
const stdout = result.stdout.split('\n')
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout))
stdout.forEach((line: string) => {
const newreplicaset = 'newreplicaset'
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
core.debug(
`found string of interest for replicaset, line is ${line}`
)
core.debug(
`substring is ${line.substring(newreplicaset.length).trim()}`
)
newReplicaSet = line
.substring(newreplicaset.length)
.trim()
.split(' ')[0]
}
})
}

Expand Down
15 changes: 14 additions & 1 deletion src/utilities/workflowAnnotationUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {cleanLabel} from '../utilities/workflowAnnotationUtils'
import {
cleanLabel,
removeInvalidLabelCharacters,
VALID_LABEL_REGEX
} from '../utilities/workflowAnnotationUtils'

describe('WorkflowAnnotationUtils', () => {
describe('cleanLabel', () => {
Expand All @@ -16,5 +20,14 @@ describe('WorkflowAnnotationUtils', () => {
cleanLabel('Workflow Name / With Slashes / And Spaces')
).toEqual('Workflow_Name_-_With_Slashes_-_And_Spaces')
})
it('should return a blank string when regex fails (https://github.com/Azure/k8s-deploy/issues/266)', () => {
const label = '持续部署'
expect(cleanLabel(label)).toEqual('github-workflow-file')

let removedInvalidChars = removeInvalidLabelCharacters(label)

const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars)
expect(regexResult).toBe(null)
})
})
})
16 changes: 12 additions & 4 deletions src/utilities/workflowAnnotationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {DeploymentConfig} from '../types/deploymentConfig'

const ANNOTATION_PREFIX = 'actions.github.com'

export const VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/

export function getWorkflowAnnotations(
lastSuccessRunSha: string,
workflowFilePath: string,
Expand Down Expand Up @@ -37,11 +39,17 @@ export function getWorkflowAnnotationKeyLabel(): string {
* @returns cleaned label
*/
export function cleanLabel(label: string): string {
let removedInvalidChars = label
let removedInvalidChars = removeInvalidLabelCharacters(label)

const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars) || [
'github-workflow-file'
]
return regexResult[0]
}

export function removeInvalidLabelCharacters(label: string): string {
return label
.replace(/\s/gi, '_')
.replace(/[\/\\\|]/gi, '-')
.replace(/[^-A-Za-z0-9_.]/gi, '')

const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
return regex.exec(removedInvalidChars)[0] || ''
}

0 comments on commit 5782616

Please sign in to comment.