Skip to content

Commit

Permalink
Merge pull request #3 from gcarrarom/dev/v0
Browse files Browse the repository at this point in the history
MVP release
  • Loading branch information
gcarrarom authored May 19, 2019
2 parents 67d6729 + 225ba86 commit a9989f4
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ test
pytestdebug.log
tests/__pycache__
coverage.xml
htmlcov
htmlcov
demo.yml
60 changes: 35 additions & 25 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ trigger:
branches:
include:
- master
- beta/*
- dev/*

pool:
vmImage: 'ubuntu-latest'
Expand All @@ -27,27 +25,24 @@ steps:
displayName: 'Use Python $(python.version)'

- script: |
branch="$(Build.SourceBranchName)"
echo "Getting version from the setup.py file..."
ApplicationVersion=$(cat setup.py | grep version | cut -d '=' -f 2 | cut -d "'" -f 2)
echo "setup.py file version: $ApplicationVersion"
echo "Testing if this version already exists in GitHub..."
echo "Get the tags first..."
tags=$(curl https://api.github.com/repos/gcarrarom/kubeconfig-cleaner-cli/tags)
if [[ $branch == *"dev"* ]]; then
workingOn=$(echo $tags | jq -r "[.[] | select(.name | contains(\"$(echo $branch | cut -d '/' -f 2)\"))] | sort_by(.name) | reverse | .[0].name ")
masterVersion=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 1)
devVersion=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 2)
devVersion=$(($devVersion + 1))
ApplicationVersion="$masterVersion.$devVersion.0"
elif [[ $branch == *"beta"* ]]; then
workingOn=$(echo $tags | jq -r "[.[] | select(.name | contains(\"$(echo $branch | cut -d '/' -f 2)\"))] | sort_by(.name) | reverse | .[0].name ")
masterVersion=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 1)
devVersion=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 2)
betaVersion=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 3)
betaVersion=$(($betaVersion + 1))
ApplicationVersion="$masterVersion.$devVersion.$betaVersion"
elif [[ $branch == "master" ]]; then
workingOn=$(echo $tags | jq -r "sort_by(.name) | reverse | .[0].name ")
version=$(echo $workingOn | cut -d 'v' -f 2 | cut -d '.' -f 1)
newVersion=$(($version + 1))
ApplicationVersion="$newVersion.0.0"
echo "check if there's a match on the version.."
Match=$(echo $tags | jq -r ".[] | select(.name == \"v$ApplicationVersion\")")
if [[ -z "$Match" ]]; then
echo "All good, this doesn't match any old versions"
else
echo "Nope, we have this already... try choosing another one ;)"
exit 100
fi
echo "Version to be used: $ApplicationVersion"
echo "##vso[task.setvariable variable=ApplicationVersion]$ApplicationVersion"
displayName: 'Get application Version'

Expand Down Expand Up @@ -85,18 +80,33 @@ steps:
CleanTargetFolder: true
displayName: 'Copying Python files to the Staging directory'

- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: 'README.MD'
TargetFolder: '$(Build.ArtifactStagingDirectory)/code'
CleanTargetFolder: true
displayName: 'Copying ReadMe.md file to the Staging directory'

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/toStage'
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/code'
includeRootFolder: true
archiveType: 'tar'
archiveFile: '$(Build.ArtifactStagingDirectory)/kcleaner-v$(ApplicationVersion)-$(Build.BuildNumber).tar.gz'
archiveFile: '$(Build.ArtifactStagingDirectory)/drop/kcleaner-v$(ApplicationVersion)-$(Build.BuildNumber).tar.gz'
replaceExistingArchive: true
displayName: 'Archiving release files to tar.gz file'

- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
PathtoPublish: '$(Build.ArtifactStagingDirectory)/drop'
ArtifactName: 'drop'
publishLocation: 'Container'
displayName: 'Publishing Artifacts'
displayName: 'Publishing Drop Artifacts'

- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/code'
ArtifactName: 'code'
publishLocation: 'Container'
displayName: 'Publishing Code Artifacts'
10 changes: 5 additions & 5 deletions kcleaner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.7
#!/usr/bin/env python
import os
import logging
import click
Expand Down Expand Up @@ -98,7 +98,7 @@ def remove_resource(config_file, removing_type):
'contexts'
]
),
default='clusters'
default='contexts'
)
@click.option(
'--kubeconfig', '-k', default=f'{Path.home()}/.kube/config'
Expand All @@ -111,7 +111,7 @@ def main(resource, name, kubeconfig):
"""
A little CLI tool to help keeping Config Files clean :)
"""
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
if resource == None:
resource = "clusters"
logging.debug(f'Using resource {resource}')
Expand All @@ -125,7 +125,7 @@ def main(resource, name, kubeconfig):
config_file = remove_resource(config_file, resource)


update_file("./config", config_file)
update_file(kubeconfig, config_file)

if __name__ == '__main__':
main()
main()
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

setup(
name='kcleaner',
version='0.0.5',
version='0.1.0',
author='Gui Martins',
url='https://fancywhale.ca/',
author_email='[email protected]',
packages=find_packages(),
include_package_data=True,
py_modules=['kcleaner'],
Expand All @@ -15,4 +18,4 @@
[console_scripts]
kcleaner=kcleaner:main
''',
)
)
25 changes: 0 additions & 25 deletions tests/kcleaner_config_file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,6 @@
from click.testing import CliRunner
from kcleaner import main

sample_config = """
apiVersion: v1
clusters:
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster
contexts:
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext
current-context: SuperCoolContext
kind: Config
preferences: {}
users:
- name: SuperCoolUserName
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
"""

runner = CliRunner()
def test_clean_non_existant_file():

Expand Down
105 changes: 103 additions & 2 deletions tests/sampleConfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,117 @@ clusters:
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster2
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster3
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster4
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster5
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster6
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster7
- cluster:
server: https://super.coolcluster.fancywhale.ca
name: SuperCoolCluster8
contexts:
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext
name: SuperCoolContext1
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext2
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext3
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext4
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext5
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext6
- context:
cluster: SuperCoolCluster
user: SuperCoolUserName
name: SuperCoolContext7
current-context: SuperCoolContext
kind: Config
preferences: {}
users:
- name: SuperCoolUserName
- name: SuperCoolUserName1
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName2
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName3
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName4
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName5
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName6
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName7
user:
auth-provider:
config:
apiserver-id: some-id-that-makes-sense
client-id: some-id-that-makes-sense
tenant-id: some-id-that-makes-sense
name: some-auth-provider
- name: SuperCoolUserName8
user:
auth-provider:
config:
Expand Down

0 comments on commit a9989f4

Please sign in to comment.