Skip to content

Commit

Permalink
Merge pull request #198 from hmcts/date
Browse files Browse the repository at this point in the history
Date
  • Loading branch information
viktoriyabogdanova authored Nov 6, 2023
2 parents c884432 + 24f99c0 commit a8c73b3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/aks-auto-start.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: aks-auto-start
on:
workflow_dispatch:
inputs:
DRYRUN:
options:
- "false"
- "true"
schedule:
- cron: '30 6 * * 1-5' # Every weekday at 6:30am BST
env:
DRYRUN: ${{ inputs.DRYRUN }}
permissions:
id-token: write
jobs:
Expand Down
4 changes: 3 additions & 1 deletion scripts/aks/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
if [[ $SKIP == "false" ]]; then
echo -e "${GREEN}About to run $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
echo az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster
az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster
if [[ $DRYRUN != "true" ]]; then
az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster
fi
else
echo -e "${AMBER}cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
fi
Expand Down
24 changes: 20 additions & 4 deletions scripts/aks/common-functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/bin/bash
# Check platform
platform=$(uname)

# Check and install missing packages
if [[ $platform == "Darwin" ]]; then
date_command=$(which gdate)
elif [[ $platform == "Linux" ]]; then
date_command=$(which date)
fi

function get_subscription_clusters() {
SUBSCRIPTION_ID=$(jq -r '.id' <<< $subscription)
Expand Down Expand Up @@ -79,14 +88,21 @@ function check_cluster_status() {

function get_current_date_seconds() {
local current_date_formatting
current_date_formatting=$(date +'%Y-%m-%d')
date -d "$current_date_formatting 00:00:00" +%s
current_date_formatting=$($date_command +'%Y-%m-%d')
$date_command -d "$current_date_formatting 00:00:00" +%s
}

function convert_date_to_timestamp() {
IFS='-' read -r day month year <<< "$1"
local valid_date="$year-$month-$day"
local timestamp=$($date_command -d "$valid_date" +%s)
echo "$timestamp"
}

function is_in_date_range() {
local start_date_seconds end_date_seconds current_date_seconds
start_date_seconds=$(date -d "$1 00:00:00" +%s)
end_date_seconds=$(date -d "$2 00:00:00" +%s)
start_date_seconds=$(convert_date_to_timestamp "$1")
end_date_seconds=$(convert_date_to_timestamp "$2")
current_date_seconds=$(get_current_date_seconds)

if [[ $current_date_seconds -ge $start_date_seconds && $current_date_seconds -le $end_date_seconds ]]; then
Expand Down

0 comments on commit a8c73b3

Please sign in to comment.