Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: k8s notifier #375

Merged
merged 30 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4a9930b
chore: initiate k8s notifier scaffold
tomaszbarwicki Nov 17, 2023
661a183
chore: add k8s release fetcher
tomaszbarwicki Nov 22, 2023
494baa9
Merge remote-tracking branch 'origin/main' into feat/k8s_notifier
tomaszbarwicki Nov 22, 2023
5ce1489
feat: add k8s release mail notification
tomaszbarwicki Nov 22, 2023
f0675dd
fix: improved styling and links presentation
tomaszbarwicki Nov 24, 2023
06a7e6b
chore: add k8s notification mail content
tomaszbarwicki Nov 24, 2023
742c835
chore: add SemVer validation to k8s release
tomaszbarwicki Nov 27, 2023
cfb8b7f
chore: move SemVer validation for PostgreSQL release
tomaszbarwicki Nov 27, 2023
abd279b
chore: add k8s notification to release notifier workflow
tomaszbarwicki Nov 27, 2023
d20b0b7
chore: rename release notifier workflow
tomaszbarwicki Nov 27, 2023
ba2ab57
docs: adopt Upgrade alignment process description for k8s
tomaszbarwicki Nov 30, 2023
d31c066
docs: add technical accounts section
tomaszbarwicki Nov 30, 2023
45537cc
docs: bold Kubernetes & PostgreSQL words
tomaszbarwicki Nov 30, 2023
b4e220c
fix: upgrade process description links
tomaszbarwicki Nov 30, 2023
126e627
chore: set proper mailing list
tomaszbarwicki Dec 5, 2023
4bccfd1
fix: ensure proper order of releases extraction
tomaszbarwicki Dec 15, 2023
021b4fa
fix: when unsuccessful parsing return from onHTML
tomaszbarwicki Dec 15, 2023
6501578
chore: replace regex with semver lib
tomaszbarwicki Dec 15, 2023
c171600
chore: update dependencies
tomaszbarwicki Dec 15, 2023
5299512
chore: add files to .gitignore
tomaszbarwicki Dec 18, 2023
ba50b04
chore: add information about disabling notification workflow for k8s
tomaszbarwicki Dec 18, 2023
0b1c78b
chore: add information about disabling notification workflow for psql
tomaszbarwicki Dec 18, 2023
d883e8f
test; add release semver unit tests
tomaszbarwicki Dec 20, 2023
b622028
fix: capture parse file error
tomaszbarwicki Dec 20, 2023
6e9addb
chore: add error return for SendMail()
tomaszbarwicki Jan 31, 2024
d38c997
chore: refactor k8s module
tomaszbarwicki Jan 31, 2024
f2bce7a
chore: refactor k8s command runner
tomaszbarwicki Jan 31, 2024
e1b7f97
test(k8s): add new release gets persisted & email contains release re…
tomaszbarwicki Jan 31, 2024
925a2a9
chore: go code format
tomaszbarwicki Jan 31, 2024
3d2bfc8
Merge branch 'main' into feat/k8s_notifier
tomaszbarwicki Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
# SPDX-License-Identifier: Apache-2.0
# #############################################################################

name: PostgreSQL new release notifier
name: Kubernetes & PostegreSQL release notifier

on:
workflow_dispatch:
inputs:
recipient:
description: "Recipent email"
description: "Notification recipent email"
required: false
schedule:
# Run every day at 01:00 at night
- cron: "0 1 * * *" # UTC time
env:
TRACTUSX_MAILINGLIST: ${{ github.event.inputs.recipient != '' && github.event.inputs.recipient || '[email protected]' }}
TRACTUSX_MAILINGLIST: ${{ github.event.inputs.recipient != '' && github.event.inputs.recipient || '[email protected]' }}
DEVSECOPS_NOTIFICATION_EMAIL: [email protected]
DEVSECOPS_NOTIFICATION_EMAIL_PASSWORD: ${{ secrets.NOTIFICATION_EMAIL_PASSWORD }}
CURRENT_ALIGNED_PSQL_VER: 15.0.0
CURRENT_ALIGNED_K8S_VER: 1.27.0
jobs:
notify:
runs-on: ubuntu-latest
Expand All @@ -48,14 +49,17 @@ jobs:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
if_no_artifact_found: warn
name: psql_release
name: releases_artifact
path: release-notifier/
- name: Run notifier
run: |
cd release-notifier
go run main.go psql
- name: Upload new release artifact
go run main.go k8s
- name: Upload release artifact
uses: actions/upload-artifact@v3
with:
name: psql_release
path: release-notifier/psql_release
name: releases_artifact
path: |
release-notifier/k8s_release
release-notifier/psql_release
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.vscode/
.idea/
dash-input.sum
release-notifier/k8s_release
release-notifier/psql_release
release-automation/tractusx-release-automation
release-notifier/release-notifier
39 changes: 29 additions & 10 deletions release-notifier/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# Release notifier
# Release Notifier

Welcome to Release Notifier tool.

Release notifier tool was designed to keep community informed about new releases and updates.
Currently it supports PostgreSQL only with potential to grow and support other applications.
Currently it supports PostgreSQL & Kubernetes with potential to grow and support other applications.

## Major Release Upgrade Process Description
## Technical Accounts

**Objective:** To streamline the process of initiating and implementing a major release upgrade, ensuring community consensus, documentation alignment, and effective communication.
Release notifier uses currently two account for its work:
- Gmail account for email notification purpose:
* eclipse.tractusx [at] gmail.com
* google account password and application secret (to send email) are stored in Vault
* recovery email set to webmaster [at] eclipse-foundation.org.

- Eclipse Foundation account:
* username: eclipsetractusx
* password: stored in Vault


## Upgrade Alignment Process Description

**Objective:** To streamline the process of initiating and implementing an upgrade, ensuring community consensus, documentation alignment, and effective communication.

1. **Initiation of Discussion:**
- A community member recognizes the need for a major release upgrade of a helm chart dependency, after receiving notification of a new release and initiates a discussion on the Tractus-X mailing list.
- A community member recognizes the need for an upgrade of a component, after receiving notification of a new release and initiates a discussion on the Tractus-X mailing list.
- In the discussion, the member provides a brief summary of the major changes, improvements, or new features that the upgrade will introduce.

2. **Collaborate and Consensus:**
Expand All @@ -21,18 +34,24 @@ Currently it supports PostgreSQL only with potential to grow and support other a
3. **Agreement to Proceed:**
- If the community reaches a consensus and agrees to proceed with the major release upgrade, formal decision is made.

4. **Update TRG 5.07 Document:**
- Community member updates PostgreSQL aligned version in the Tractus-X Release Guide (TRG) 5.07 following the [process](https://eclipse-tractusx.github.io/docs/release/).
4. **Update Aligned Version in the TRG Document:**
- Community member updates aligned version in the respective Tractus-X Release Guide following the [process](https://eclipse-tractusx.github.io/docs/release/).
- **PostgreSQL**: [TRG 5.07](https://eclipse-tractusx.github.io/docs/release/trg-5/trg-5-07)
- **Kubernetes**: [TRG 5.10](https://eclipse-tractusx.github.io/docs/release/trg-5/trg-5-10)

5. **Update GitHub Workflow:**
- Within the project's GitHub repository, update environment variable CURRENT_ALIGNED_PSQL_VER in the [psql-release-notifier workflow](https://github.com/eclipse-tractusx/sig-release/blob/main/.github/workflows/psql-release-notifier.yaml#L31) to reflect the agreed-upon version for the major release.
- Within the project's GitHub repository, update environment variable to reflect the agreed-upon version for the major release.
- **PostgreSQL**: CURRENT_ALIGNED_PSQL_VER at [release-notifier](https://github.com/eclipse-tractusx/sig-release/blob/main/.github/workflows/release-notifier.yaml#L35) workflow
- **Kubernetes**: CURRENT_ALIGNED_K8S_VER at [release-notifier](https://github.com/eclipse-tractusx/sig-release/blob/main/.github/workflows/release-notifier.yaml#L36) workflow

6. **Send Communication:**
- Once the TRG and GitHub workflow are aligned with the new version, member prepares a formal communication.
- The communication details the major release upgrade, its purpose, features, and any critical instructions for the community.
- The communication details the component relevant release upgrade, its purpose, features, and any critical instructions for the community.

7. **Implementation:**
- The major release upgrade is carried out as per the defined [upgrade plan](TBP), with close attention to the documentation, codebase, and any testing or validation procedures as required.
- The upgrade is carried out as per the defined upgrade plan, with close attention to the documentation, codebase, and any testing or validation procedures as required.
- **PostgreSQL**: [upgrade plan](TBP)
- **Kubernetes**: [upgrade plan](TBP)

9. **Ongoing Feedback and Improvement:**
- Continuous feedback from the community is encouraged and used to further improve the upgrade process for future releases.
Expand Down
61 changes: 61 additions & 0 deletions release-notifier/cmd/k8s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/
package cmd

import (
"log"
"release-notifier/internal/k8s"

"github.com/spf13/cobra"
)

// k8sCmd represents the k8s command
var k8sCmd = &cobra.Command{
Use: "k8s",
Short: "Sends out notification of new Kubernetes release",
Long: `Sends out notification of new Kubernetes release
to a mailing list:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
log.Println("Kubernetes release notifier called.")
if k8s.IsNewRelease() {
if err := k8s.Notify(); err != nil {
log.Fatalln(err)
}
log.Println("Email Sent!")
}
},
}

func init() {
rootCmd.AddCommand(k8sCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// k8sCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// k8sCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
6 changes: 3 additions & 3 deletions release-notifier/cmd/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package cmd

import (
"github.com/spf13/cobra"
"log"
"os"
"github.com/spf13/cobra"
"release-notifier/internal/psql"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func psqlNotifier() {
latestRelease := psql.GetLatestRel()
prevRelease := psql.GetPrevRelFromArtifact()

if latestRelease != prevRelease {
if latestRelease != prevRelease && latestRelease != "" {
log.Printf("New release is out: %v\n", latestRelease)
alignedRelease := os.Getenv("CURRENT_ALIGNED_PSQL_VER")
log.Printf("Current aligned version: %v\n", alignedRelease)
Expand All @@ -68,4 +68,4 @@ func psqlNotifier() {
} else {
log.Println("No new release :(")
}
}
}
1 change: 1 addition & 0 deletions release-notifier/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module release-notifier
go 1.20

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/gocolly/colly v1.2.0
github.com/spf13/cobra v1.8.0
)
Expand Down
2 changes: 2 additions & 0 deletions release-notifier/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
Expand Down
117 changes: 117 additions & 0 deletions release-notifier/internal/k8s/k8snotifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package k8s

import (
"bytes"
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/gocolly/colly"
"log"
"os"
"release-notifier/internal/mail"
"strings"
"text/template"
)

const mailTemplate = "templates/mail-k8s.html.tmpl"
const artifactName = "k8s_release"

func getLatestRel() string {
release, _ := semver.NewVersion("0.0.0")
website := "https://kubernetes.io/releases/"

log.Println("Querying", website)
c := colly.NewCollector()

c.OnError(func(_ *colly.Response, err error) {
log.Println("Can't load the page: ", err)
})

c.OnHTML("span.release-inline-value", func(e *colly.HTMLElement) {
if !strings.Contains(e.Text, "release") {
return
}
r, err := semver.NewVersion(strings.Split(e.Text, " ")[0])
if err != nil {
return
}
if r.Compare(release) == 1 {
release = r
}
})

c.Visit(website)
return release.String()
}

func getRelFromArtifact() string {
data, err := os.ReadFile(artifactName)

if err != nil {
return ""
}

release := string(data)
return release
}

func IsNewRelease() bool {
latestRelease := getLatestRel()
prevRelease := getRelFromArtifact()
if latestRelease != prevRelease {
log.Printf("New release is out: %v\n", latestRelease)
if err := os.WriteFile(artifactName, []byte(latestRelease), 0644); err != nil {
log.Fatalln(err)
return false
}
return true
}
log.Println("No new release :(")
return false
}

func buildContent(mailTemplate string) ([]byte, error) {
newRelease := getRelFromArtifact()
alignedRelease := os.Getenv("CURRENT_ALIGNED_K8S_VER")
var buff bytes.Buffer
mimeHeaders := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
buff.Write([]byte(fmt.Sprintf("Subject: Action Required: Kubernetes New Release (%s)\n%s\n\n", newRelease, mimeHeaders)))
t, err := template.ParseFiles(mailTemplate)
t.Execute(&buff, struct {
NewK8SRelease string
AlignedK8SRelease string
}{
NewK8SRelease: newRelease,
AlignedK8SRelease: alignedRelease,
})
if err != nil {
return nil, err
}
return buff.Bytes(), nil
}

func Notify() error {
content, err := buildContent(mailTemplate)
if err != nil {
return err
}
return mail.SendMail(content)
}
Loading
Loading