Skip to content

Commit

Permalink
Merge pull request #111 from hemanthnakkina/merge-feat-manifest
Browse files Browse the repository at this point in the history
Merge feat manifest to main
  • Loading branch information
javacruft authored Feb 8, 2024
2 parents a24c305 + 3fc153d commit a433e1e
Show file tree
Hide file tree
Showing 73 changed files with 4,547 additions and 1,634 deletions.
9 changes: 5 additions & 4 deletions cloud/etc/deploy-microceph/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ resource "juju_application" "microceph" {
units = length(var.machine_ids) # need to manage the number of units

charm {
name = "microceph"
channel = var.charm_microceph_channel
name = "microceph"
channel = var.charm_microceph_channel
revision = var.charm_microceph_revision
base = "[email protected]"
}

config = {
config = merge({
snap-channel = var.microceph_channel
}
}, var.charm_microceph_config)
}

# juju_offer.microceph_offer will be created
Expand Down
13 changes: 13 additions & 0 deletions cloud/etc/deploy-microceph/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@

variable "charm_microceph_channel" {
description = "Operator channel for microceph deployment"
type = string
default = "edge"
}

variable "charm_microceph_revision" {
description = "Operator channel revision for microceph deployment"
type = number
default = null
}

variable "charm_microceph_config" {
description = "Operator config for microceph deployment"
type = map(string)
default = {}
}

variable "microceph_channel" {
description = "K8S channel to deploy, not the operator channel"
default = "latest/stable"
Expand Down
9 changes: 5 additions & 4 deletions cloud/etc/deploy-microk8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ resource "juju_application" "microk8s" {
units = length(var.machine_ids) # need to manage the number of units

charm {
name = "microk8s"
channel = var.charm_microk8s_channel
name = "microk8s"
channel = var.charm_microk8s_channel
revision = var.charm_microk8s_revision
base = "[email protected]"
}

config = {
config = merge({
channel = var.microk8s_channel
addons = join(" ", [for key, value in var.addons : "${key}:${value}"])
disable_cert_reissue = true
kubelet_serialize_image_pulls = false
skip_verify = true
}
}, var.charm_microk8s_config)
}
13 changes: 13 additions & 0 deletions cloud/etc/deploy-microk8s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@

variable "charm_microk8s_channel" {
description = "Operator channel for microk8s deployment"
type = string
default = "legacy/stable"
}

variable "charm_microk8s_revision" {
description = "Operator channel revision for microk8s deployment"
type = number
default = null
}

variable "charm_microk8s_config" {
description = "Operator config for microk8s deployment"
type = map(string)
default = {}
}

variable "microk8s_channel" {
description = "K8S channel to deploy, not the operator channel"
default = "1.28-strict/stable"
Expand Down
9 changes: 5 additions & 4 deletions cloud/etc/deploy-openstack-hypervisor/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ resource "juju_application" "openstack-hypervisor" {
units = length(var.machine_ids) # need to manage the number of units

charm {
name = "openstack-hypervisor"
channel = var.charm_channel
name = "openstack-hypervisor"
channel = var.charm_channel
revision = var.charm_revision
base = "[email protected]"
}

config = {
config = merge({
snap-channel = var.snap_channel
}
}, var.charm_config)

}

Expand Down
12 changes: 12 additions & 0 deletions cloud/etc/deploy-openstack-hypervisor/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ variable "charm_channel" {
default = "2023.2/edge"
}

variable "charm_revision" {
description = "Charm channel revision to deploy openstack-hypervisor charm from"
type = number
default = null
}

variable "charm_config" {
description = "Charm config to deploy openstack-hypervisor charm from"
type = map(string)
default = {}
}

variable "openstack_model" {
description = "Name of OpenStack model."
type = string
Expand Down
7 changes: 5 additions & 2 deletions cloud/etc/deploy-sunbeam-machine/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ resource "juju_application" "sunbeam-machine" {
units = length(var.machine_ids) # need to manage the number of units

charm {
name = "sunbeam-machine"
channel = var.charm_channel
name = "sunbeam-machine"
channel = var.charm_channel
revision = var.charm_revision
base = "[email protected]"
}

config = var.charm_config

}
12 changes: 12 additions & 0 deletions cloud/etc/deploy-sunbeam-machine/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ variable "charm_channel" {
default = "latest/edge"
}

variable "charm_revision" {
description = "Charm channel revision to deploy openstack-hypervisor charm from"
type = number
default = null
}

variable "charm_config" {
description = "Charm config to deploy openstack-hypervisor charm from"
type = map(string)
default = {}
}

variable "machine_model" {
description = "Name of model to deploy sunbeam-machine into."
type = string
Expand Down
2 changes: 2 additions & 0 deletions sunbeam-microcluster/api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ var Endpoints = []rest.Endpoint{
jujuusersCmd,
jujuuserCmd,
configCmd,
manifestsCmd,
manifestCmd,
}
91 changes: 91 additions & 0 deletions sunbeam-microcluster/api/manifests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package api

import (
"encoding/json"
"net/http"
"net/url"

"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/microcluster/rest"
"github.com/canonical/microcluster/state"
"github.com/gorilla/mux"

"github.com/canonical/snap-openstack/sunbeam-microcluster/api/types"
"github.com/canonical/snap-openstack/sunbeam-microcluster/sunbeam"
)

// /1.0/manifests endpoint.
var manifestsCmd = rest.Endpoint{
Path: "manifests",

Get: rest.EndpointAction{Handler: cmdManifestsGetAll, ProxyTarget: true},
Post: rest.EndpointAction{Handler: cmdManifestsPost, ProxyTarget: true},
}

// /1.0/manifests/<manifestid> endpoint.
// /1.0/manifests/latest will give the latest inserted manifest record
var manifestCmd = rest.Endpoint{
Path: "manifests/{manifestid}",

Get: rest.EndpointAction{Handler: cmdManifestGet, ProxyTarget: true},
Delete: rest.EndpointAction{Handler: cmdManifestDelete, ProxyTarget: true},
}

func cmdManifestsGetAll(s *state.State, _ *http.Request) response.Response {

manifests, err := sunbeam.ListManifests(s)
if err != nil {
return response.InternalError(err)
}

return response.SyncResponse(true, manifests)
}

func cmdManifestGet(s *state.State, r *http.Request) response.Response {
var manifestid string
manifestid, err := url.PathUnescape(mux.Vars(r)["manifestid"])
if err != nil {
return response.InternalError(err)
}
manifest, err := sunbeam.GetManifest(s, manifestid)
if err != nil {
if err, ok := err.(api.StatusError); ok {
if err.Status() == http.StatusNotFound {
return response.NotFound(err)
}
}
return response.InternalError(err)
}

return response.SyncResponse(true, manifest)
}

func cmdManifestsPost(s *state.State, r *http.Request) response.Response {
var req types.Manifest

err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
return response.InternalError(err)
}

err = sunbeam.AddManifest(s, req.ManifestID, req.Data)
if err != nil {
return response.InternalError(err)
}

return response.EmptySyncResponse
}

func cmdManifestDelete(s *state.State, r *http.Request) response.Response {
manifestid, err := url.PathUnescape(mux.Vars(r)["manifestid"])
if err != nil {
return response.SmartError(err)
}
err = sunbeam.DeleteManifest(s, manifestid)
if err != nil {
return response.InternalError(err)
}

return response.EmptySyncResponse
}
12 changes: 12 additions & 0 deletions sunbeam-microcluster/api/types/manifests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package types provides shared types and structs.
package types

// Manifests holds list of manifest type
type Manifests []Manifest

// Manifest structure to hold manifest applytime and manifest data
type Manifest struct {
ManifestID string `json:"manifestid" yaml:"manifestid"`
AppliedDate string `json:"applieddate" yaml:"applieddate"`
Data string `json:"data" yaml:"data"`
}
2 changes: 1 addition & 1 deletion sunbeam-microcluster/database/config.mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func getConfigItems(ctx context.Context, stmt *sql.Stmt, args ...any) ([]ConfigI
return objects, nil
}

// getConfigItems can be used to run handwritten query strings to return a slice of objects.
// getConfigItemsRaw can be used to run handwritten query strings to return a slice of objects.
func getConfigItemsRaw(ctx context.Context, tx *sql.Tx, sql string, args ...any) ([]ConfigItem, error) {
objects := make([]ConfigItem, 0)

Expand Down
2 changes: 1 addition & 1 deletion sunbeam-microcluster/database/jujuuser.mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func getJujuUsers(ctx context.Context, stmt *sql.Stmt, args ...any) ([]JujuUser,
return objects, nil
}

// getJujuUsers can be used to run handwritten query strings to return a slice of objects.
// getJujuUsersRaw can be used to run handwritten query strings to return a slice of objects.
func getJujuUsersRaw(ctx context.Context, tx *sql.Tx, sql string, args ...any) ([]JujuUser, error) {
objects := make([]JujuUser, 0)

Expand Down
Loading

0 comments on commit a433e1e

Please sign in to comment.