-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37ddc07
commit 4c568fd
Showing
13 changed files
with
349 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This workflow will build and release a golang-based microservice | ||
# using goreleaser any time a new version tag is pushed to the repository | ||
|
||
name: Release with goreleaser | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
permissions: write-all # Necessary for creating containers | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Go 1.21 | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.21 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Docker Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-tags: 1 | ||
fetch-depth: 1 | ||
- name: Release with goreleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
version: latest | ||
args: release --clean |
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 @@ | ||
dist |
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 |
---|---|---|
|
@@ -36,7 +36,6 @@ dockers: | |
- LICENSE | ||
- CHANGELOG.md | ||
- README.md | ||
- .version | ||
|
||
archives: | ||
- format: tar.gz | ||
|
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,16 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.0.4] - 2024-01-17 | ||
|
||
### Added | ||
|
||
- Initial release | ||
- Created SMD client | ||
- Added memory-based store | ||
- Able to provide cloud-init payloads that work with newly booted nodes | ||
- Build and release with goreleaser |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# harbor | ||
# Cloud-Init | ||
|
||
Microservice that servers out cloud-init configs | ||
OpenCHAMI cloud-init server that retrieves detailed inventory information from SMD and uses it to create cloud-init payloads customized for each node in an ochami-based cluster |
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,167 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/OpenCHAMI/cloud-init/internal/memstore" | ||
"github.com/OpenCHAMI/cloud-init/internal/smdclient" | ||
"github.com/OpenCHAMI/cloud-init/pkg/citypes" | ||
"github.com/gin-gonic/gin" | ||
"github.com/gosimple/slug" | ||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
type CiHandler struct { | ||
store ciStore | ||
sm *smdclient.SMDClient | ||
} | ||
|
||
func NewCiHandler(s ciStore, c *smdclient.SMDClient) *CiHandler { | ||
return &CiHandler{ | ||
store: s, | ||
sm: c, | ||
} | ||
} | ||
|
||
// ListEntries godoc | ||
// @Summary List all cloud-init entries | ||
// @Description List all cloud-init entries | ||
// @Produce json | ||
// @Success 200 {object} map[string]CI | ||
// @Router /harbor [get] | ||
func (h CiHandler) ListEntries(c *gin.Context) { | ||
ci, err := h.store.List() | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
} | ||
|
||
c.JSON(200, ci) | ||
} | ||
|
||
// AddEntry godoc | ||
// @Summary Add a new cloud-init entry | ||
// @Description Add a new cloud-init entry | ||
// @Accept json | ||
// @Produce json | ||
// @Param ci body CI true "Cloud-init entry to add" | ||
// @Success 200 {string} string "name of the new entry" | ||
// @Failure 400 {string} string "bad request" | ||
// @Failure 500 {string} string "internal server error" | ||
// @Router /harbor [post] | ||
func (h CiHandler) AddEntry(c *gin.Context) { | ||
var ci citypes.CI | ||
if err := c.ShouldBindJSON(&ci); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
id := slug.Make(ci.Name) | ||
|
||
err := h.store.Add(id, ci) | ||
if err != nil { | ||
if err == memstore.ExistingEntryErr { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, ci.Name) | ||
} | ||
|
||
// GetEntry godoc | ||
// @Summary Get a cloud-init entry | ||
// @Description Get a cloud-init entry | ||
// @Produce json | ||
// @Param id path string true "ID of the cloud-init entry to get" | ||
// @Success 200 {object} CI | ||
// @Failure 404 {string} string "not found" | ||
// @Router /harbor/{id} [get] | ||
func (h CiHandler) GetEntry(c *gin.Context) { | ||
id := c.Param("id") | ||
|
||
ci, err := h.store.Get(id, h.sm) | ||
if err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
} | ||
|
||
c.JSON(200, ci) | ||
} | ||
|
||
func (h CiHandler) GetUserData(c *gin.Context) { | ||
id := c.Param("id") | ||
|
||
ci, err := h.store.Get(id, h.sm) | ||
if err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
} | ||
ud, err := yaml.Marshal(ci.CIData.UserData) | ||
if err != nil { | ||
fmt.Print(err) | ||
} | ||
s := fmt.Sprintf("#cloud-config\n%s", string(ud[:])) | ||
//c.Header("Content-Type", "text/yaml") | ||
c.Data(200, "text/yaml", []byte(s)) | ||
} | ||
|
||
func (h CiHandler) GetMetaData(c *gin.Context) { | ||
id := c.Param("id") | ||
|
||
ci, err := h.store.Get(id, h.sm) | ||
if err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
} | ||
|
||
c.YAML(200, ci.CIData.MetaData) | ||
} | ||
|
||
func (h CiHandler) GetVendorData(c *gin.Context) { | ||
id := c.Param("id") | ||
|
||
ci, err := h.store.Get(id, h.sm) | ||
if err != nil { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
} | ||
|
||
c.YAML(200, ci.CIData.VendorData) | ||
} | ||
|
||
func (h CiHandler) UpdateEntry(c *gin.Context) { | ||
var ci citypes.CI | ||
if err := c.ShouldBindJSON(&ci); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
id := c.Param("id") | ||
|
||
err := h.store.Update(id, ci) | ||
if err != nil { | ||
if err == memstore.NotFoundErr { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, id) | ||
} | ||
|
||
func (h CiHandler) DeleteEntry(c *gin.Context) { | ||
id := c.Param("id") | ||
|
||
err := h.store.Remove(id) | ||
if err != nil { | ||
if err == memstore.NotFoundErr { | ||
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{"status": "success"}) | ||
} |
Oops, something went wrong.