This repository has been archived by the owner on Mar 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This takes yaml manifests and adds the same annotations as the webhook handler would. This is useful to test and validate manifests, e.g: ./annotate .ci/workflow.yaml | argo lint /dev/stdin
- Loading branch information
1 parent
e042236
commit d740752
Showing
2 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/google/go-github/v24/github" | ||
handler "github.com/itskoko/k8s-webhook-handler" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
func main() { | ||
var ( | ||
evType = flag.String("-type", "push", "Event type") | ||
action = flag.String("-action", "", "Event action") | ||
revision = flag.String("-revision", "0000000000000000000000000000000000000000", "Revision") | ||
ref = flag.String("-ref", "refs/heads/master", "Ref") | ||
before = flag.String("-before", "0000000000000000000000000000000000000000", "Before") | ||
repoURL = flag.String("-url", "git://github.com/itskoko/k8s-webhook-handler.git", "git URL") | ||
sshUser = flag.String("-ssh-user", "git", "SSH user") | ||
) | ||
flag.Parse() | ||
files := flag.Args() | ||
if len(files) == 0 { | ||
log.Fatal("Usage: annotate [flags] file-to-annotate [more-files-to-annotate...]") | ||
} | ||
u, err := url.Parse(*repoURL) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
var ( | ||
sshURL = fmt.Sprintf("%s@%s:%s", *sshUser, u.Host, u.Path) | ||
fullName = strings.TrimSuffix(u.Path, ".git") | ||
) | ||
|
||
repo := &github.Repository{ | ||
FullName: &fullName, | ||
GitURL: repoURL, | ||
SSHURL: &sshURL, | ||
} | ||
annotations := (&handler.Event{ | ||
Type: *evType, | ||
Action: *action, | ||
Revision: *revision, | ||
Ref: *ref, | ||
Before: *before, | ||
Repository: repo, | ||
}).Annotations() | ||
|
||
for _, file := range flag.Args() { | ||
fh, err := os.Open(file) | ||
if err != nil { | ||
log.Fatalf("Couldn't read file %s: %s", err) | ||
} | ||
defer fh.Close() | ||
obj, err := handler.Decode(fh) | ||
meta.NewAccessor().SetAnnotations(obj, annotations) | ||
if err := unstructured.UnstructuredJSONScheme.Encode(obj, os.Stdout); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} |
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