join.image defaults to the public image #30
No files matched your search
@@ -66,6 +66,7 @@ snapshot: /var/lib/obs-beacon/backup/beacon.db # a consistent copy for the bac
|
||||
# agent_url: "https://beacon.example.org:8461" # default: alerts.public_url's host, agent_listen's port
|
||||
# packages_dir: /var/lib/obs-beacon/agent-packages # a release's agent .deb/.rpm + SHA256SUMS, served at /agent-packages/
|
||||
# packages_url: "https://..." # or a release download URL with the same files
|
||||
# image: registry.example.org/ops/obs-beacond # where clusters pull the cluster agent; default ghcr.io/coffey-labs/cairnobs
|
||||
|
||||
# Agents managed in this file instead. `obs-beacond token` prints a new
|
||||
# token and its hash; the token goes on the host, only the hash goes here.
|
||||
|
||||
@@ -14,5 +14,6 @@ join:
|
||||
# image doesn't carry them, so packages_dir doesn't apply here.)
|
||||
# packages_url: https://downloads.example.org/cairnobs/v0.1.0
|
||||
# Where clusters pull this image from, for Configure, Clusters (it
|
||||
# carries the cluster agent too). Without a tag, this version's.
|
||||
# image: ghcr.io/coffey-labs/cairnobs
|
||||
# carries the cluster agent too); ghcr.io/coffey-labs/cairnobs unless set.
|
||||
# Without a tag, this version's.
|
||||
# image: registry.example.org/ops/obs-beacond
|
||||
+1
-1
@@ -87,7 +87,7 @@ obs-beacond.yaml:
|
||||
| `agent_url` | the agent listener as new hosts reach it, e.g. `https://monitor.example.org:8461`. Default: `alerts.public_url`'s host with `agent_listen`'s port |
|
||||
| `packages_dir` | a directory of agent `.deb`/`.rpm` files and `SHA256SUMS` from a release, served at `/agent-packages/` for install.sh |
|
||||
| `packages_url` | otherwise, a release download URL install.sh fetches them from |
|
||||
| `image` | where clusters pull the obs-beacond image from, which carries the cluster agent, e.g. `registry.example.org/ops/obs-beacond`. Without a tag, this obs-beacond's version. Adding a cluster needs it |
|
||||
| `image` | where clusters pull the obs-beacond image from, which carries the cluster agent: default `ghcr.io/coffey-labs/cairnobs`; set it, e.g. `registry.example.org/ops/obs-beacond`, for clusters that can't reach that. Without a tag, this obs-beacond's version (a development build takes `:latest` of the default) |
|
||||
|
||||
Joining needs `database` and the TLS agent listener. obs-beacond serves
|
||||
`/install.sh` and `/cluster.yaml` on `listen`, unauthenticated; they hold
|
||||
|
||||
+3
-2
@@ -154,8 +154,9 @@ obs-beacond. It reads the cluster with `get`, `list` and `watch` only and
|
||||
sends its nodes, pods, controllers, jobs and volumes over the agent port,
|
||||
as a host's agent does.
|
||||
|
||||
1. Set `join.image` in obs-beacond.yaml to where your clusters pull this
|
||||
image from (formats.md, Joining). For the cluster obs-beacond runs in,
|
||||
1. Clusters pull this image from `ghcr.io/coffey-labs/cairnobs`; if yours
|
||||
can't reach it, set `join.image` in obs-beacond.yaml to your copy
|
||||
(formats.md, Joining). For the cluster obs-beacond runs in,
|
||||
`join.agent_url` may be the Service: `https://obs-beacond.<namespace>.svc:8461`.
|
||||
Other clusters need the agent Route or load balancer.
|
||||
2. **Configure › Clusters › Add a cluster** gives one command, good once
|
||||
|
||||
@@ -459,9 +459,17 @@ func TestJoinACluster(t *testing.T) {
|
||||
r := newRig(t, t.TempDir(), server.NewAgentToken())
|
||||
r.cfg.Join.AgentURL = r.ts.URL
|
||||
api := admin(t, r)
|
||||
if code, out := api(http.MethodPost, "/api/v1/agents/join", `{"name":"prod","cluster":true}`); code != http.StatusConflict ||
|
||||
!strings.Contains(fmtJSON(out), "join.image") {
|
||||
// Without join.image, the manifest names the public image.
|
||||
if code, out := api(http.MethodPost, "/api/v1/agents/join", `{"name":"pub","cluster":true}`); code != http.StatusOK {
|
||||
t.Fatalf("a cluster without join.image: %d %v", code, out)
|
||||
} else {
|
||||
req := httptest.NewRequest(http.MethodGet, "/cluster.yaml", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+out["token"].(string))
|
||||
rec := httptest.NewRecorder()
|
||||
r.srv.Handler().ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `image: "ghcr.io/coffey-labs/cairnobs:`) {
|
||||
t.Fatalf("manifest without join.image: %d\n%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
r.cfg.Join.Image = "registry.example.org/ops/obs-beacond"
|
||||
code, out := api(http.MethodPost, "/api/v1/agents/join", `{"name":"prod","cluster":true}`)
|
||||
|
||||
@@ -10,6 +10,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -18,10 +19,26 @@ import (
|
||||
"github.com/cairnobs/cairnobs/internal/version"
|
||||
)
|
||||
|
||||
// clusterImage is join.image, with this obs-beacond's version as the tag
|
||||
// when it has none.
|
||||
// DefaultClusterImage is where clusters pull the cluster agent from when
|
||||
// join.image isn't set: the public image every release publishes.
|
||||
const DefaultClusterImage = "ghcr.io/coffey-labs/cairnobs"
|
||||
|
||||
// releaseVersion is a version a release is tagged with: 0.1.0 or
|
||||
// 0.1.0-rc.2, not a development build's dev or 0.1.0-3-gabc1234-dirty.
|
||||
var releaseVersion = regexp.MustCompile(`^\d+\.\d+\.\d+(-rc\.\d+)?$`)
|
||||
|
||||
// clusterImage is join.image, or DefaultClusterImage, with this
|
||||
// obs-beacond's version as the tag when it has none. A development build
|
||||
// has no image of its own on the public registry, so with the default it
|
||||
// takes :latest.
|
||||
func (srv *Server) clusterImage() string {
|
||||
img := srv.cfg.Join.Image
|
||||
if img == "" {
|
||||
img = DefaultClusterImage
|
||||
if v := strings.TrimPrefix(version.Version, "v"); !releaseVersion.MatchString(v) {
|
||||
return img + ":latest"
|
||||
}
|
||||
}
|
||||
last := img[strings.LastIndex(img, "/")+1:]
|
||||
if strings.Contains(last, ":") || strings.Contains(last, "@") {
|
||||
return img
|
||||
|
||||
@@ -5,8 +5,33 @@ import (
|
||||
"testing"
|
||||
|
||||
clusteragent "github.com/cairnobs/cairnobs/deploy/kubernetes/cluster-agent"
|
||||
"github.com/cairnobs/cairnobs/internal/version"
|
||||
)
|
||||
|
||||
// Without join.image clusters pull the public image at this version, or
|
||||
// :latest from a development build; a set join.image gets this version
|
||||
// unless it names a tag or digest itself.
|
||||
func TestClusterImage(t *testing.T) {
|
||||
was := version.Version
|
||||
t.Cleanup(func() { version.Version = was })
|
||||
for _, c := range []struct{ image, version, want string }{
|
||||
{"", "0.1.0", "ghcr.io/coffey-labs/cairnobs:0.1.0"},
|
||||
{"", "v0.2.0-rc.3", "ghcr.io/coffey-labs/cairnobs:0.2.0-rc.3"},
|
||||
{"", "dev", "ghcr.io/coffey-labs/cairnobs:latest"},
|
||||
{"", "v0.1.0-3-gabc1234-dirty", "ghcr.io/coffey-labs/cairnobs:latest"},
|
||||
{"registry.example.org:5000/ops/obs-beacond", "0.1.0", "registry.example.org:5000/ops/obs-beacond:0.1.0"},
|
||||
{"registry.example.org/ops/obs-beacond", "dev", "registry.example.org/ops/obs-beacond:dev"},
|
||||
{"registry.example.org/ops/obs-beacond:pinned", "0.1.0", "registry.example.org/ops/obs-beacond:pinned"},
|
||||
{"registry.example.org/ops/obs-beacond@sha256:abc", "0.1.0", "registry.example.org/ops/obs-beacond@sha256:abc"},
|
||||
} {
|
||||
version.Version = c.version
|
||||
srv := &Server{cfg: &Config{Join: JoinConfig{Image: c.image}}}
|
||||
if got := srv.clusterImage(); got != c.want {
|
||||
t.Errorf("join.image %q at %s: %s, want %s", c.image, c.version, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /cluster.yaml?cert_renew=1 is the same manifest with -cert-renew and
|
||||
// cert-renew.yaml's role; without it, neither.
|
||||
func TestClusterManifestCertRenew(t *testing.T) {
|
||||
|
||||
@@ -48,9 +48,9 @@ type JoinConfig struct {
|
||||
// download URL holding the same files.
|
||||
PackagesURL string `yaml:"packages_url"`
|
||||
// Image is where clusters pull the obs-beacond image from, which
|
||||
// carries the cluster agent: e.g. registry.example.org/ops/obs-beacond.
|
||||
// Without a tag, this obs-beacond's version is used. Add a cluster
|
||||
// needs it.
|
||||
// carries the cluster agent: e.g. registry.example.org/ops/obs-beacond,
|
||||
// for clusters that can't reach the public one. Without it,
|
||||
// DefaultClusterImage. Without a tag, this obs-beacond's version is used.
|
||||
Image string `yaml:"image"`
|
||||
}
|
||||
|
||||
@@ -281,15 +281,9 @@ func (srv *Server) joinUnavailable(r *http.Request) string {
|
||||
}
|
||||
|
||||
// clusterJoinUnavailable says why clusters can't join here; "" when they
|
||||
// can.
|
||||
// can. It's what stops hosts joining: the image has a default.
|
||||
func (srv *Server) clusterJoinUnavailable(r *http.Request) string {
|
||||
if why := srv.joinUnavailable(r); why != "" {
|
||||
return why
|
||||
}
|
||||
if srv.cfg.Join.Image == "" {
|
||||
return "Adding a cluster needs join.image in obs-beacond.yaml: where your clusters pull the obs-beacond image from (it carries the cluster agent)."
|
||||
}
|
||||
return ""
|
||||
return srv.joinUnavailable(r)
|
||||
}
|
||||
|
||||
// handleAgents lists the agents and the pending join tokens.
|
||||
|
||||
Reference in new issue
Block a user