This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RHIDP-2246] Fix reconciliation issue when referenced ConfigMap/Secre…
…t has a dot (`.`) in its name (#363) * Add tests highlighting the issue * Convert volume names to valid K8s resource names Using https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ as reference. * Address review comments Co-authored-by: Gennady Azarenkov <[email protected]> --------- Co-authored-by: Gennady Azarenkov <[email protected]>
- Loading branch information
1 parent
49c8caa
commit adc11eb
Showing
4 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestToRFC1123Label(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in string | ||
want string | ||
}{ | ||
// The inputs below are all valid names for K8s ConfigMaps or Secrets. | ||
|
||
{ | ||
name: "should replace invalid characters with a dash", | ||
in: "kube-root-ca.crt", | ||
want: "kube-root-ca-crt", | ||
}, | ||
{ | ||
name: "all-numeric string should remain unchanged", | ||
in: "123456789", | ||
want: "123456789", | ||
}, | ||
{ | ||
name: "should truncate up to the maximum length and remove leading and trailing dashes", | ||
in: "ppxkgq.df-yyatvyrgjtwivunibicne-bvyyotvonbrtfv-awylmrez.ksvqjw-z.xpgdi", /* 70 characters */ | ||
want: "ppxkgq-df-yyatvyrgjtwivunibicne-bvyyotvonbrtfv-awylmrez-ksvqjw", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ToRFC1123Label(tt.in); got != tt.want { | ||
t.Errorf("ToRFC1123Label() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |