Skip to content

Commit

Permalink
sending zora version to saas as header (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusfm authored Mar 24, 2023
1 parent 71bb553 commit 2e8ef47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions charts/zora/templates/operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ spec:
- --cronjob-serviceaccount-name=zora-plugins
- --saas-workspace-id={{ .Values.saas.workspaceID }}
- --saas-server={{ .Values.saas.server }}
- --version={{ .Chart.Version }}
image: "{{ .Values.operator.image.repository }}:{{ .Values.operator.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.operator.image.pullPolicy }}
ports:
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func main() {
var cronJobServiceAccount string
var saasWorkspaceID string
var saasServer string
var version string

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -75,6 +76,7 @@ func main() {
flag.StringVar(&cronJobServiceAccount, "cronjob-serviceaccount-name", "zora-plugins", "Name of ServiceAccount to be configured, appended to ClusterRoleBinding and used by CronJobs")
flag.StringVar(&saasWorkspaceID, "saas-workspace-id", "", "Your workspace ID in Zora SaaS")
flag.StringVar(&saasServer, "saas-server", "http://localhost:3003", "Address for Zora's saas server")
flag.StringVar(&version, "version", "v0.4.4", "Zora version")

opts := zap.Options{
Development: true,
Expand All @@ -101,7 +103,7 @@ func main() {
var onClusterUpdate, onClusterDelete saas.ClusterHook
var onClusterScanUpdate, onClusterScanDelete saas.ClusterScanHook
if saasWorkspaceID != "" {
saasClient, err := saas.NewClient(saasServer, "v1alpha1", saasWorkspaceID, http.DefaultClient)
saasClient, err := saas.NewClient(saasServer, version, saasWorkspaceID, http.DefaultClient)
if err != nil {
setupLog.Error(err, "unable to create SaaS client", "workspaceID", saasWorkspaceID)
os.Exit(1)
Expand Down
9 changes: 7 additions & 2 deletions pkg/saas/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
)

const (
workspacePathF = "zora/api/%s/workspaces/%s"
workspacePathF = "zora/api/v1alpha1/workspaces/%s"
clusterPathF = "namespaces/%s/clusters/%s"
versionHeader = "x-zora-version"
)

var allowedStatus = []int{
Expand Down Expand Up @@ -57,7 +58,7 @@ func NewClient(baseURL, version, workspaceID string, httpclient *http.Client) (C
if err != nil {
return nil, err
}
u.Path = path.Join(u.Path, fmt.Sprintf(workspacePathF, version, workspaceID))
u.Path = path.Join(u.Path, fmt.Sprintf(workspacePathF, workspaceID))
return &client{
version: version,
baseURL: u,
Expand All @@ -77,6 +78,7 @@ func (r *client) PutCluster(ctx context.Context, cluster v1alpha1.Cluster) error
return err
}
req.Header.Set("content-type", "application/json")
req.Header.Set(versionHeader, r.version)
res, err := r.client.Do(req)
if err != nil {
return err
Expand All @@ -91,6 +93,7 @@ func (r *client) DeleteCluster(ctx context.Context, namespace, name string) erro
if err != nil {
return err
}
req.Header.Set(versionHeader, r.version)
res, err := r.client.Do(req)
if err != nil {
return err
Expand All @@ -110,6 +113,7 @@ func (r *client) PutClusterScan(ctx context.Context, namespace, name string, plu
return err
}
req.Header.Set("content-type", "application/json")
req.Header.Set(versionHeader, r.version)
res, err := r.client.Do(req)
if err != nil {
return err
Expand All @@ -125,6 +129,7 @@ func (r *client) DeleteClusterScan(ctx context.Context, namespace, name string)
return err
}
res, err := r.client.Do(req)
req.Header.Set(versionHeader, r.version)
if err != nil {
return err
}
Expand Down

0 comments on commit 2e8ef47

Please sign in to comment.