Skip to content

Commit

Permalink
Customize api server port
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <daishan@acorn.io>
  • Loading branch information
StrongMonkey authored and brandond committed Jun 29, 2023
1 parent 9f2eeec commit 7ca672b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pkg/controllers/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ type Controller struct {
jobCache batchcontroller.JobCache
apply apply.Apply
recorder record.EventRecorder
apiServerPort string
}

func Register(ctx context.Context,
systemNamespace, managedBy string,
systemNamespace, managedBy, apiServerPort string,
k8s kubernetes.Interface,
apply apply.Apply,
recorder record.EventRecorder,
Expand All @@ -96,6 +97,7 @@ func Register(ctx context.Context,
jobs: jobs,
jobCache: jobCache,
recorder: recorder,
apiServerPort: apiServerPort,
}

c.apply = apply.
Expand Down Expand Up @@ -309,7 +311,7 @@ func (c *Controller) getJobAndRelatedResources(chart *v1.HelmChart) (*batch.Job,
}

// get the default job and configmaps
job, valuesSecret, contentConfigMap := job(chart)
job, valuesSecret, contentConfigMap := job(chart, c.apiServerPort)

// check if a HelmChartConfig is registered for this Helm chart
config, err := c.confCache.Get(chart.Namespace, chart.Name)
Expand Down Expand Up @@ -340,7 +342,7 @@ func (c *Controller) getJobAndRelatedResources(chart *v1.HelmChart) (*batch.Job,
}, nil
}

func job(chart *v1.HelmChart) (*batch.Job, *corev1.Secret, *corev1.ConfigMap) {
func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret, *corev1.ConfigMap) {
jobImage := strings.TrimSpace(chart.Spec.JobImage)
if jobImage == "" {
jobImage = DefaultJobImage
Expand Down Expand Up @@ -481,7 +483,7 @@ func job(chart *v1.HelmChart) (*batch.Job, *corev1.Secret, *corev1.ConfigMap) {
Value: "127.0.0.1"},
{
Name: "KUBERNETES_SERVICE_PORT",
Value: "6443"},
Value: apiServerPort},
{
Name: "BOOTSTRAP",
Value: "true"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSetVals(t *testing.T) {
func TestInstallJob(t *testing.T) {
assert := assert.New(t)
chart := NewChart()
job, _, _ := job(chart)
job, _, _ := job(chart, "6443")
assert.Equal("helm-install-traefik", job.Name)
assert.Equal(DefaultJobImage, job.Spec.Template.Spec.Containers[0].Image)
assert.Equal("helm-traefik", job.Spec.Template.Spec.ServiceAccountName)
Expand All @@ -49,7 +49,7 @@ func TestDeleteJob(t *testing.T) {
chart := NewChart()
deleteTime := metav1.NewTime(time.Time{})
chart.DeletionTimestamp = &deleteTime
job, _, _ := job(chart)
job, _, _ := job(chart, "6443")
assert.Equal("helm-delete-traefik", job.Name)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Register(ctx context.Context, systemNamespace, controllerName string, cfg c
chart.Register(ctx,
systemNamespace,
controllerName,
"6443",
appCtx.K8s,
appCtx.Apply,
recorder,
Expand Down

0 comments on commit 7ca672b

Please sign in to comment.