Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-notifications-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
GilUpstream authored Nov 15, 2023
2 parents cb4a752 + 6ede1a8 commit 5b87b84
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 32 deletions.
26 changes: 18 additions & 8 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2815,17 +2815,24 @@ func TestGenerateAppsUsingPullRequestGenerator(t *testing.T) {
{
name: "Generate an application from a go template application set manifest using a pull request generator",
params: []map[string]interface{}{{
"number": "1",
"branch": "branch1",
"branch_slug": "branchSlug1",
"head_sha": "089d92cbf9ff857a39e6feccd32798ca700fb958",
"head_short_sha": "089d92cb",
"labels": []string{"label1"}}},
"number": "1",
"branch": "branch1",
"branch_slug": "branchSlug1",
"head_sha": "089d92cbf9ff857a39e6feccd32798ca700fb958",
"head_short_sha": "089d92cb",
"branch_slugify_default": "feat/a_really+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
"branch_slugify_smarttruncate_disabled": "feat/areallylongpullrequestnametotestargoslugificationandbranchnameshorteningfeature",
"branch_slugify_smarttruncate_enabled": "feat/testwithsmarttruncateenabledramdomlonglistofcharacters",
"labels": []string{"label1"}},
},
template: v1alpha1.ApplicationSetTemplate{
ApplicationSetTemplateMeta: v1alpha1.ApplicationSetTemplateMeta{
Name: "AppSet-{{.branch}}-{{.number}}",
Labels: map[string]string{
"app1": "{{index .labels 0}}",
"app1": "{{index .labels 0}}",
"branch-test1": "AppSet-{{.branch_slugify_default | slugify }}",
"branch-test2": "AppSet-{{.branch_slugify_smarttruncate_disabled | slugify 49 false }}",
"branch-test3": "AppSet-{{.branch_slugify_smarttruncate_enabled | slugify 50 true }}",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand All @@ -2844,7 +2851,10 @@ func TestGenerateAppsUsingPullRequestGenerator(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "AppSet-branch1-1",
Labels: map[string]string{
"app1": "label1",
"app1": "label1",
"branch-test1": "AppSet-feat-a-really-long-pull-request-name-to-test-argo",
"branch-test2": "AppSet-feat-areallylongpullrequestnametotestargoslugific",
"branch-test3": "AppSet-feat",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down
50 changes: 50 additions & 0 deletions applicationset/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"unsafe"

"github.com/Masterminds/sprig/v3"
"github.com/gosimple/slug"
"github.com/valyala/fasttemplate"
"sigs.k8s.io/yaml"

Expand All @@ -32,6 +33,7 @@ func init() {
delete(sprigFuncMap, "expandenv")
delete(sprigFuncMap, "getHostByName")
sprigFuncMap["normalize"] = SanitizeName
sprigFuncMap["slugify"] = SlugifyName
sprigFuncMap["toYaml"] = toYAML
sprigFuncMap["fromYaml"] = fromYAML
sprigFuncMap["fromYamlArray"] = fromYAMLArray
Expand Down Expand Up @@ -434,6 +436,54 @@ func NormalizeBitbucketBasePath(basePath string) string {
return basePath
}

// SlugifyName generates a URL-friendly slug from the provided name and additional options.
// The slug is generated in accordance with the following rules:
// 1. The generated slug will be URL-safe and suitable for use in URLs.
// 2. The maximum length of the slug can be specified using the `maxSize` argument.
// 3. Smart truncation can be enabled or disabled using the `EnableSmartTruncate` argument.
// 4. The input name can be any string value that needs to be converted into a slug.
//
// Args:
// - args: A variadic number of arguments where:
// - The first argument (if provided) is an integer specifying the maximum length of the slug.
// - The second argument (if provided) is a boolean indicating whether smart truncation is enabled.
// - The last argument (if provided) is the input name that needs to be slugified.
// If no name is provided, an empty string will be used.
//
// Returns:
// - string: The generated URL-friendly slug based on the input name and options.
func SlugifyName(args ...interface{}) string {
// Default values for arguments
maxSize := 50
EnableSmartTruncate := true
name := ""

// Process the arguments
for idx, arg := range args {
switch idx {
case len(args) - 1:
name = arg.(string)
case 0:
maxSize = arg.(int)
case 1:
EnableSmartTruncate = arg.(bool)
default:
log.Errorf("Bad 'slugify' arguments.")
}
}

sanitizedName := SanitizeName(name)

// Configure slug generation options
slug.EnableSmartTruncate = EnableSmartTruncate
slug.MaxLength = maxSize

// Generate the slug from the input name
urlSlug := slug.Make(sanitizedName)

return urlSlug
}

func getTlsConfigWithCACert(scmRootCAPath string) *tls.Config {

tlsConfig := &tls.Config{}
Expand Down
37 changes: 37 additions & 0 deletions applicationset/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,43 @@ func TestNormalizeBitbucketBasePath(t *testing.T) {
}
}

func TestSlugify(t *testing.T) {
for _, c := range []struct {
branch string
smartTruncate bool
length int
expectedBasePath string
}{
{
branch: "feat/a_really+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
smartTruncate: false,
length: 50,
expectedBasePath: "feat-a-really-long-pull-request-name-to-test-argo",
},
{
branch: "feat/a_really+long_pull_request_name_to_test_argo_slugification_and_branch_name_shortening_feature",
smartTruncate: true,
length: 53,
expectedBasePath: "feat-a-really-long-pull-request-name-to-test-argo",
},
{
branch: "feat/areallylongpullrequestnametotestargoslugificationandbranchnameshorteningfeature",
smartTruncate: true,
length: 50,
expectedBasePath: "feat",
},
{
branch: "feat/areallylongpullrequestnametotestargoslugificationandbranchnameshorteningfeature",
smartTruncate: false,
length: 50,
expectedBasePath: "feat-areallylongpullrequestnametotestargoslugifica",
},
} {
result := SlugifyName(c.length, c.smartTruncate, c.branch)
assert.Equal(t, c.expectedBasePath, result, c.branch)
}
}

func TestGetTLSConfig(t *testing.T) {
// certParsed, err := tls.X509KeyPair(test.Cert, test.PrivateKey)
// require.NoError(t, err)
Expand Down
14 changes: 7 additions & 7 deletions docs/developer-guide/release-process-and-cadence.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

These are the upcoming releases dates:

| Release | Release Candidate 1 | General Availability | Release Champion | Checklist |
|---------|-----------------------|----------------------|-------------------------------------------------------|---------------------------------------------------------------|
| v2.6 | Monday, Dec. 19, 2022 | Monday, Feb. 6, 2023 | [William Tam](https://github.com/wtam2018) | [checklist](https://github.com/argoproj/argo-cd/issues/11563) |
| v2.7 | Monday, Mar. 20, 2023 | Monday, May 1, 2023 | [Pavel Kostohrys](https://github.com/pasha-codefresh) | [checklist](https://github.com/argoproj/argo-cd/issues/12762) |
| v2.8 | Monday, Jun. 26, 2023 | Monday, Aug. 7, 2023 | [Keith Chong](https://github.com/keithchong) | [checklist](https://github.com/argoproj/argo-cd/issues/13742) |
| v2.9 | Monday, Sep. 18, 2023 | Monday, Nov. 6, 2023 | [Leonardo Almeida](https://github.com/leoluz) | [checklist](https://github.com/argoproj/argo-cd/issues/14078) |
| v2.10 | Monday, Dec. 18, 2023 | Monday, Feb. 5, 2024 |
| Release | Release Candidate 1 | General Availability | Release Champion | Release Approver |Checklist |
|---------|-----------------------|----------------------|-------------------------------------------------------|-------------------------------------------------------|---------------------------------------------------------------|
| v2.6 | Monday, Dec. 19, 2022 | Monday, Feb. 6, 2023 | [William Tam](https://github.com/wtam2018) | [William Tam](https://github.com/wtam2018) | [checklist](https://github.com/argoproj/argo-cd/issues/11563) |
| v2.7 | Monday, Mar. 20, 2023 | Monday, May 1, 2023 | [Pavel Kostohrys](https://github.com/pasha-codefresh) | [Pavel Kostohrys](https://github.com/pasha-codefresh) | [checklist](https://github.com/argoproj/argo-cd/issues/12762) |
| v2.8 | Monday, Jun. 26, 2023 | Monday, Aug. 7, 2023 | [Keith Chong](https://github.com/keithchong) | [Keith Chong](https://github.com/keithchong) | [checklist](https://github.com/argoproj/argo-cd/issues/13742) |
| v2.9 | Monday, Sep. 18, 2023 | Monday, Nov. 6, 2023 | [Leonardo Almeida](https://github.com/leoluz) | [Leonardo Almeida](https://github.com/leoluz) | [checklist](https://github.com/argoproj/argo-cd/issues/14078) |
| v2.10 | Monday, Dec. 18, 2023 | Monday, Feb. 5, 2024 | [Katie Lamkin](https://github.com/kmlamkin9) | | [checklist](https://github.com/argoproj/argo-cd/issues/16339) |
| v2.11 | Monday, Mar. 18, 2024 | Monday, May 6, 2024 |
| v2.12 | Monday, Jun. 17, 2024 | Monday, Aug. 5, 2024 |

Expand Down
23 changes: 23 additions & 0 deletions docs/operator-manual/applicationset/GoTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ An additional `normalize` function makes any string parameter usable as a valid
with hyphens and truncating at 253 characters. This is useful when making parameters safe for things like Application
names.

Another function has `slugify` function has been added which, by default, sanitizes and smart truncate (means doesn't cut a word into 2). This function accepts a couple of arguments:
- The first argument (if provided) is an integer specifying the maximum length of the slug.
- The second argument (if provided) is a boolean indicating whether smart truncation is enabled.
- The last argument (if provided) is the input name that needs to be slugified.

#### Usage example

```
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: test-appset
spec:
...
template:
metadata:
name: 'hellos3-{{.name}}-{{ cat .branch | slugify 23 }}'
annotations:
label-1: '{{ cat .branch | slugify }}'
label-2: '{{ cat .branch | slugify 23 }}'
label-3: '{{ cat .branch | slugify 50 false }}'
```

If you want to customize [options defined by text/template](https://pkg.go.dev/text/template#Template.Option), you can
add the `goTemplateOptions: ["opt1", "opt2", ...]` key to your ApplicationSet next to `goTemplate: true`. Note that at
the time of writing, there is only one useful option defined, which is `missingkey=error`.
Expand Down
47 changes: 41 additions & 6 deletions docs/user-guide/kustomize.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ To use Kustomize with an overlay, point your path to the overlay.
If you're generating resources, you should read up how to ignore those generated resources using the [`IgnoreExtraneous` compare option](compare-options.md).

## Patches
Patches are a way to kustomize resources using inline configurations in Argo CD applications. This allows for kustomizing without kustomization file. `patches` follow the same logic as the corresponding Kustomization. Any patches that target existing Kustomization file will be merged.
Patches are a way to kustomize resources using inline configurations in Argo CD applications. `patches` follow the same logic as the corresponding Kustomization. Any patches that target existing Kustomization file will be merged.

The following Kustomization can be done similarly in an Argo CD application.
This Kustomize example sources manifests from the `/kustomize-guestbook` folder of the `argoproj/argocd-example-apps` repository, and patches the `Deployment` to use port `443` on the container.
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
name: kustomize-inline-example
namespace: test1
resources:
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-deployment.yaml
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-svc.yaml
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/kustomize-guestbook/
patches:
- target:
kind: Deployment
Expand All @@ -42,7 +41,8 @@ patches:
path: /spec/template/spec/containers/0/ports/0/containerPort
value: 443
```
Application will clone the repository, use the specified path, then kustomize using inline patches configuration.
This `Application` does the equivalent using the inline `kustomize.patches` configuration.
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
Expand All @@ -57,7 +57,7 @@ spec:
server: https://kubernetes.default.svc
project: default
source:
path: guestbook
path: kustomize-guestbook
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: master
kustomize:
Expand All @@ -71,6 +71,41 @@ spec:
value: 443
```

The inline kustomize patches work well with `ApplicationSets`, too. Instead of maintaining a patch or overlay for each cluster, patches can now be done in the `Application` template and utilize attributes from the generators. For example, with [`external-dns`](https://github.com/kubernetes-sigs/external-dns/) to set the [`txt-owner-id`](https://github.com/kubernetes-sigs/external-dns/blob/e1adc9079b12774cccac051966b2c6a3f18f7872/docs/registry/registry.md?plain=1#L6) to the cluster name.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: external-dns
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters: {}
template:
metadata:
name: 'external-dns'
spec:
project: default
source:
repoURL: https://github.com/kubernetes-sigs/external-dns/
targetRevision: v0.14.0
path: kustomize
kustomize:
patches:
- target:
kind: Deployment
name: external-dns
patch: |-
- op: add
path: /spec/template/spec/containers/0/args/3
value: --txt-owner-id={{.name}} # patch using attribute from generator
destination:
name: 'in-cluster'
namespace: default
```

## Private Remote Bases

If you have remote bases that are either (a) HTTPS and need username/password (b) SSH and need SSH private key, then they'll inherit that from the app's repo.
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^6.4.0",
"@types/react-virtualized": "^9.21.21",
"@types/superagent": "^4.1.15",
"@types/superagent": "^4.1.21",
"ansi-to-react": "^6.1.6",
"argo-ui": "git+https://github.com/argoproj/argo-ui.git",
"buffer": "^6.0.3",
Expand Down
15 changes: 5 additions & 10 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1903,12 +1903,7 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/node@*":
version "16.3.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.1.tgz#24691fa2b0c3ec8c0d34bfcfd495edac5593ebb4"
integrity sha512-N87VuQi7HEeRJkhzovao/JviiqKjDKMVKxKMfUvSKw+MbkbW8R0nA3fi/MQhhlxV2fQ+2ReM+/Nt4efdrJx3zA==

"@types/node@20.6.3":
"@types/node@*", "@types/node@20.6.3":
version "20.6.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.6.3.tgz#5b763b321cd3b80f6b8dde7a37e1a77ff9358dd9"
integrity sha512-HksnYH4Ljr4VQgEy2lTStbCKv/P590tmPe5HqOnv9Gprffgv5WXAY+Y5Gqniu0GGqeTCUdBnzC3QSrzPkBkAMA==
Expand Down Expand Up @@ -2058,10 +2053,10 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c"
integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==

"@types/superagent@^4.1.15":
version "4.1.15"
resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-4.1.15.tgz#63297de457eba5e2bc502a7609426c4cceab434a"
integrity sha512-mu/N4uvfDN2zVQQ5AYJI/g4qxn2bHB6521t1UuH09ShNWjebTqN0ZFuYK9uYjcgmI0dTQEs+Owi1EO6U0OkOZQ==
"@types/superagent@^4.1.21":
version "4.1.21"
resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-4.1.21.tgz#78e2c2d6894c5f8ece228f0df4912906133d97c3"
integrity sha512-yrbAccEEY9+BSa1wji3ry8R3/BdW9kyWnjkRKctrtw5ebn/k2a2CsMeaQ7dD4iLfomgHkomBVIVgOFRMV4XYHA==
dependencies:
"@types/cookiejar" "*"
"@types/node" "*"
Expand Down

0 comments on commit 5b87b84

Please sign in to comment.