Skip to content

Commit 7985c23

Browse files
committed
fix(finalizer): use correct max length and name
This fixes #193. As stated, the documentation defines the max length to 63 instead of 254 and the name should be a domain name.
1 parent 6efa95e commit 7985c23

File tree

9 files changed

+68
-45
lines changed

9 files changed

+68
-45
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Documentation
3+
about: Suggest a topic that is not correctly documented (or not documented at all)
4+
title: ''
5+
labels: documentation
6+
assignees: ''
7+
---
8+
9+
**Describe the missing piece of documentation**
10+
Describe what you miss in the docs.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ nuget/
1111
artifacts/
1212
coverage/
1313
.tmp/
14+
.nuke/temp
15+
.nuke/build.schema.json
1416

1517
# Build results
1618
[Dd]ebug/

.nuke

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nuke/parameters.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./build.schema.json",
3+
"Solution": "DotnetOperatorSdk.sln"
4+
}

build.cmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/build.sh "$@"
4+
:; exit $?
5+
6+
@ECHO OFF
7+
powershell -ExecutionPolicy ByPass -NoProfile "%~dp0build.ps1" %*

build.ps1

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ Param(
66

77
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
88

9-
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { exit 1 }
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
1010
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
1111

1212
###########################################################################
1313
# CONFIGURATION
1414
###########################################################################
1515

1616
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
17-
$TempDirectory = "$PSScriptRoot\\.tmp"
17+
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
1818

1919
$DotNetGlobalFile = "$PSScriptRoot\\global.json"
20-
$DotNetInstallUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
21-
$DotNetChannel = "LTS"
20+
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
21+
$DotNetChannel = "Current"
2222

2323
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
2424
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
2526

2627
###########################################################################
2728
# EXECUTION
@@ -32,37 +33,37 @@ function ExecSafe([scriptblock] $cmd) {
3233
if ($LASTEXITCODE) { exit $LASTEXITCODE }
3334
}
3435

35-
# If global.json exists, load expected version
36-
if (Test-Path $DotNetGlobalFile) {
37-
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
38-
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
39-
$DotNetVersion = $DotNetGlobal.sdk.version
40-
}
41-
}
42-
43-
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
36+
# If dotnet CLI is installed globally and it matches requested version, use for execution
4437
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
45-
(!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) {
38+
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
4639
$env:DOTNET_EXE = (Get-Command "dotnet").Path
4740
}
4841
else {
49-
$DotNetDirectory = "$TempDirectory\dotnet-win"
50-
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
51-
5242
# Download install script
5343
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
54-
New-Item -ItemType Directory -Path $TempDirectory | Out-Null
44+
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
45+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
5546
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
5647

48+
# If global.json exists, load expected version
49+
if (Test-Path $DotNetGlobalFile) {
50+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
51+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
52+
$DotNetVersion = $DotNetGlobal.sdk.version
53+
}
54+
}
55+
5756
# Install by channel or version
57+
$DotNetDirectory = "$TempDirectory\dotnet-win"
5858
if (!(Test-Path variable:DotNetVersion)) {
5959
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
6060
} else {
6161
ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
6262
}
63+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
6364
}
6465

6566
Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"
6667

67-
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false }
68+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
6869
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

build.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
echo $(bash --version 2>&1 | head -n 1)
3+
bash --version 2>&1 | head -n 1
44

55
set -eo pipefail
66
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
@@ -10,53 +10,53 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
1010
###########################################################################
1111

1212
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13-
TEMP_DIRECTORY="$SCRIPT_DIR//.tmp"
13+
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
1414

1515
DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
16-
DOTNET_INSTALL_URL="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
17-
DOTNET_CHANNEL="LTS"
16+
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
17+
DOTNET_CHANNEL="Current"
1818

1919
export DOTNET_CLI_TELEMETRY_OPTOUT=1
2020
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
export DOTNET_MULTILEVEL_LOOKUP=0
2122

2223
###########################################################################
2324
# EXECUTION
2425
###########################################################################
2526

2627
function FirstJsonValue {
27-
perl -nle 'print $1 if m{"'$1'": "([^"]+)",?}' <<< ${@:2}
28+
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
2829
}
2930

30-
# If global.json exists, load expected version
31-
if [ -f "$DOTNET_GLOBAL_FILE" ]; then
32-
DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE"))
33-
if [ "$DOTNET_VERSION" == "" ]; then
34-
unset DOTNET_VERSION
35-
fi
36-
fi
37-
38-
# If dotnet is installed locally, and expected version is not set or installation matches the expected version
39-
if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version 2>&1) == "$DOTNET_VERSION") ]]; then
31+
# If dotnet CLI is installed globally and it matches requested version, use for execution
32+
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
4033
export DOTNET_EXE="$(command -v dotnet)"
4134
else
42-
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
43-
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
44-
4535
# Download install script
4636
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
4737
mkdir -p "$TEMP_DIRECTORY"
4838
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
4939
chmod +x "$DOTNET_INSTALL_FILE"
50-
40+
41+
# If global.json exists, load expected version
42+
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
43+
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
44+
if [[ "$DOTNET_VERSION" == "" ]]; then
45+
unset DOTNET_VERSION
46+
fi
47+
fi
48+
5149
# Install by channel or version
52-
if [ -z ${DOTNET_VERSION+x} ]; then
50+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
51+
if [[ -z ${DOTNET_VERSION+x} ]]; then
5352
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
5453
else
5554
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
5655
fi
56+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
5757
fi
5858

5959
echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"
6060

61-
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false
61+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
6262
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

build/Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Build : NukeBuild
4040
IEnumerable<Project> Projects => Solution.AllProjects.Where(p => p.SolutionFolder?.Name == "src");
4141

4242
string PackageReleaseNotes => (ReleaseNotes.Length > MaxReleaseNoteLength
43-
? ReleaseNotes.Substring(0, MaxReleaseNoteLength)
43+
? ReleaseNotes[..MaxReleaseNoteLength]
4444
: ReleaseNotes)
4545
.Replace(",", "%2c")
4646
.Replace(";", "%3b");

src/KubeOps/Operator/Finalizer/IResourceFinalizer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace KubeOps.Operator.Finalizer
1212
public interface IResourceFinalizer<in TEntity>
1313
where TEntity : IKubernetesObject<V1ObjectMeta>
1414
{
15-
private const byte MaxNameLength = 254;
15+
private const byte MaxNameLength = 63;
1616

1717
/// <summary>
1818
/// Unique identifier for this finalizer.
@@ -24,9 +24,9 @@ string Identifier
2424
get
2525
{
2626
var crd = CustomEntityDefinitionExtensions.CreateResourceDefinition<TEntity>();
27-
var name = $"{GetType().Name.ToLowerInvariant()}.{crd.Singular}.finalizers.{crd.Group}";
27+
var name = $"{crd.Group}/{GetType().Name.ToLowerInvariant()}finalizer";
2828
return name.Length > MaxNameLength
29-
? name.Substring(0, MaxNameLength)
29+
? name[..MaxNameLength]
3030
: name;
3131
}
3232
}

0 commit comments

Comments
 (0)