Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Lamarre <[email protected]>
  • Loading branch information
alexandreLamarre committed Jan 14, 2025
1 parent b1a1d2d commit f313157
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
{
"linters": "revive",
"text": "should have comment or be unexported"
},
{
"path": "_test.go",
"linters": "revive"
}
],
"exclude-files": [
Expand Down
2 changes: 1 addition & 1 deletion cmd/helm-project-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DummyOperator struct {
Kubeconfig string `usage:"Kubeconfig file"`
}

func (o *DummyOperator) Run(cmd *cobra.Command, args []string) error {
func (o *DummyOperator) Run(cmd *cobra.Command, _ []string) error {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
Expand Down
30 changes: 14 additions & 16 deletions internal/helm-project-operator/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ var (

// hardcoded labels / annotations / values
const (
// TODO : this will be subject to change as I update the code

labelProjectId = "field.cattle.io/projectId"
annoProjectId = "field.cattle.io/projectId"
labelProjectID = "field.cattle.io/projectId"
annoProjectID = "field.cattle.io/projectId"

labelHelmProj = "helm.cattle.io/projectId"
labelOperatedByHelmProj = "helm.cattle.io/helm-project-operated"
Expand Down Expand Up @@ -100,7 +98,7 @@ func (h *helmInstaller) build() (*exec.Cmd, error) {
return cmd, nil
}

func newHelmInstaller(opts ...helmInstallerOption) *helmInstaller {
func newHelmInstaller(opts ...HelmInstallerOption) *helmInstaller {
h := &helmInstaller{
helmInstallOptions: helmInstallerDefaultOptions(),
}
Expand Down Expand Up @@ -130,39 +128,39 @@ type helmInstallOptions struct {
values map[string]string
}

type helmInstallerOption func(*helmInstallOptions)
type HelmInstallerOption func(*helmInstallOptions)

func WithContext(ctx context.Context) helmInstallerOption {
func WithContext(ctx context.Context) HelmInstallerOption {
return func(h *helmInstallOptions) {
h.ctx = ctx
}
}

func WithCreateNamespace() helmInstallerOption {
func WithCreateNamespace() HelmInstallerOption {
return func(h *helmInstallOptions) {
h.createNamespace = true
}
}

func WithNamespace(namespace string) helmInstallerOption {
func WithNamespace(namespace string) HelmInstallerOption {
return func(h *helmInstallOptions) {
h.namespace = namespace
}
}

func WithReleaseName(releaseName string) helmInstallerOption {
func WithReleaseName(releaseName string) HelmInstallerOption {
return func(h *helmInstallOptions) {
h.releaseName = releaseName
}
}

func WithChartRegistry(chartRegistry string) helmInstallerOption {
func WithChartRegistry(chartRegistry string) HelmInstallerOption {
return func(h *helmInstallOptions) {
h.chartRegistry = chartRegistry
}
}

func WithValue(key string, value string) helmInstallerOption {
func WithValue(key string, value string) HelmInstallerOption {
return func(h *helmInstallOptions) {
if _, ok := h.values[key]; ok {
panic("duplicate helm value set, likely uninteded behaviour")
Expand Down Expand Up @@ -273,10 +271,10 @@ var _ = Describe("E2E helm project operator tests", Ordered, Label("kubernetes")
Name: "e2e-hpo",
Labels: map[string]string{
// Note : this will be rejected by webhook if rancher/rancher is managing this cluster
labelProjectId: "p-example",
labelProjectID: "p-example",
},
Annotations: map[string]string{
annoProjectId: fmt.Sprintf("local:%s", testProjectName),
annoProjectID: fmt.Sprintf("local:%s", testProjectName),
},
},
}
Expand All @@ -295,12 +293,12 @@ var _ = Describe("E2E helm project operator tests", Ordered, Label("kubernetes")
}
Eventually(Object(projNs), 60*time.Second).Should(ExistAnd(
HaveLabels(
labelProjectId, testProjectName,
labelProjectID, testProjectName,
labelOperatedByHelmProj, "true",
labelHelmProj, testProjectName,
),
HaveAnnotations(
labelProjectId, testProjectName,
labelProjectID, testProjectName,
),
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type handler struct {
func Register(
ctx context.Context,
apply apply.Apply,
opts common.HardeningOptions,
_ common.HardeningOptions,
namespaces corecontroller.NamespaceController,
namespaceCache corecontroller.NamespaceCache,
serviceaccounts corecontroller.ServiceAccountController,
Expand All @@ -48,7 +48,7 @@ func Register(
namespaces.OnChange(ctx, "harden-hpo-operated-namespace", h.OnChange)
}

func (h *handler) OnChange(name string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
func (h *handler) OnChange( /*name*/ _ string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
if namespace == nil {
return namespace, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *handler) resolveHardenedProjectRegistrationNamespaceData(namespace, nam
return nil, nil
}

func (h *handler) resolveServiceAccount(namespace, name string, serviceAccount *corev1.ServiceAccount) ([]relatedresource.Key, error) {
func (h *handler) resolveServiceAccount(namespace, name string, _ *corev1.ServiceAccount) ([]relatedresource.Key, error) {
// check if name matches
if name == defaultServiceAccountName {
return []relatedresource.Key{{
Expand All @@ -56,7 +56,7 @@ func (h *handler) resolveServiceAccount(namespace, name string, serviceAccount *
return nil, nil
}

func (h *handler) resolveNetworkPolicy(namespace, name string, networkPolicy *networkingv1.NetworkPolicy) ([]relatedresource.Key, error) {
func (h *handler) resolveNetworkPolicy(namespace, name string, _ *networkingv1.NetworkPolicy) ([]relatedresource.Key, error) {
// check if name matches
if name == defaultNetworkPolicyName {
return []relatedresource.Key{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Register(

// Single Namespace Handler

func (h *handler) OnSingleNamespaceChange(name string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
func (h *handler) OnSingleNamespaceChange( /*name*/ _ string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
if namespace.Name != h.systemNamespace {
// enqueue system namespace to ensure that rolebindings are updated

Expand All @@ -129,7 +129,7 @@ func (h *handler) OnSingleNamespaceChange(name string, namespace *corev1.Namespa

// Multiple Namespaces Handler

func (h *handler) OnMultiNamespaceChange(name string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
func (h *handler) OnMultiNamespaceChange( /*name*/ _ string, namespace *corev1.Namespace) (*corev1.Namespace, error) {
if namespace == nil {
logrus.Debugf("OnMultiNamespaceChange() called with no namespace.")
return namespace, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (h *handler) resolveProjectRegistrationNamespaceData(namespace, name string
return nil, nil
}

func (h *handler) resolveConfigMap(namespace, name string, configmap *corev1.ConfigMap) ([]relatedresource.Key, error) {
func (h *handler) resolveConfigMap(namespace, name string, _ *corev1.ConfigMap) ([]relatedresource.Key, error) {
// check if name matches
if name == h.getConfigMapName() {
return []relatedresource.Key{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Register(
})

remove.RegisterScopedOnRemoveHandler(ctx, projectHelmCharts, "on-project-helm-chart-remove",
func(key string, obj runtime.Object) (bool, error) {
func( /* key */ _ string, obj runtime.Object) (bool, error) {
if obj == nil {
return false, nil
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func (h *handler) OnChange(projectHelmChart *v1alpha1.ProjectHelmChart, projectH
return objs, projectHelmChartStatus, nil
}

func (h *handler) OnRemove(key string, projectHelmChart *v1alpha1.ProjectHelmChart) (*v1alpha1.ProjectHelmChart, error) {
func (h *handler) OnRemove( /* key */ _ string, projectHelmChart *v1alpha1.ProjectHelmChart) (*v1alpha1.ProjectHelmChart, error) {
if projectHelmChart == nil {
return nil, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h *handler) initResolvers(ctx context.Context) {

// Project Release Namespace

func (h *handler) resolveProjectReleaseNamespace(namespace, name string, obj runtime.Object) ([]relatedresource.Key, error) {
func (h *handler) resolveProjectReleaseNamespace( /*namespace, name*/ _, _ string, obj runtime.Object) ([]relatedresource.Key, error) {
if obj == nil {
return nil, nil
}
Expand All @@ -62,7 +62,7 @@ func (h *handler) resolveProjectReleaseNamespace(namespace, name string, obj run

// System Namespace Data

func (h *handler) resolveSystemNamespaceData(namespace, name string, obj runtime.Object) ([]relatedresource.Key, error) {
func (h *handler) resolveSystemNamespaceData(namespace /* name*/, _ string, obj runtime.Object) ([]relatedresource.Key, error) {
if namespace != h.systemNamespace {
return nil, nil
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (h *handler) resolveProjectRegistrationNamespaceData(namespace, name string
return nil, nil
}

func (h *handler) resolveProjectRegistrationNamespaceRoleBinding(namespace, name string, rb *rbacv1.RoleBinding) ([]relatedresource.Key, error) {
func (h *handler) resolveProjectRegistrationNamespaceRoleBinding(namespace /*name*/, _ string, rb *rbacv1.RoleBinding) ([]relatedresource.Key, error) {
namespaceObj, err := h.namespaceCache.Get(namespace)
if err != nil {
logrus.Debugf("Namespace not found %s: ", namespace)
Expand Down Expand Up @@ -134,7 +134,7 @@ func (h *handler) resolveProjectRegistrationNamespaceRoleBinding(namespace, name
return keys, nil
}

func (h *handler) resolveClusterRoleBinding(namespace, name string, crb *rbacv1.ClusterRoleBinding) ([]relatedresource.Key, error) {
func (h *handler) resolveClusterRoleBinding( /*namespace, name*/ _, _ string, crb *rbacv1.ClusterRoleBinding) ([]relatedresource.Key, error) {
// we want to re-enqueue the ProjectHelmChart if the rolebinding's ref points to one of the operator default roles
_, isDefaultRoleRef := common.IsDefaultClusterRoleRef(h.opts, crb.RoleRef.Name)
if !isDefaultRoleRef {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (h *handler) resolveClusterRoleBinding(namespace, name string, crb *rbacv1.

// Project Release Namespace Data

func (h *handler) resolveProjectReleaseNamespaceData(namespace, name string, obj runtime.Object) ([]relatedresource.Key, error) {
func (h *handler) resolveProjectReleaseNamespaceData( /*namespace, name*/ _, _ string, obj runtime.Object) ([]relatedresource.Key, error) {
if obj == nil {
return nil, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/helm-project-operator/pkg/controllers/project/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// getCleanupStatus returns the status on seeing the cleanup label on a ProjectHelmChart
func (h *handler) getCleanupStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getCleanupStatus(projectHelmChart *v1alpha1.ProjectHelmChart, _ v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
return v1alpha1.ProjectHelmChartStatus{
Status: "AwaitingOperatorRedeployment",
StatusMessage: fmt.Sprintf(
Expand All @@ -21,7 +21,7 @@ func (h *handler) getCleanupStatus(projectHelmChart *v1alpha1.ProjectHelmChart,
}

// getUnableToCreateHelmReleaseStatus returns the status on seeing a conflicting ProjectHelmChart already tracking the desired Helm release
func (h *handler) getUnableToCreateHelmReleaseStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus, err error) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getUnableToCreateHelmReleaseStatus(projectHelmChart *v1alpha1.ProjectHelmChart, _ v1alpha1.ProjectHelmChartStatus, err error) v1alpha1.ProjectHelmChartStatus {
releaseNamespace, releaseName := h.getReleaseNamespaceAndName(projectHelmChart)
return v1alpha1.ProjectHelmChartStatus{
Status: "UnableToCreateHelmRelease",
Expand All @@ -34,15 +34,15 @@ func (h *handler) getUnableToCreateHelmReleaseStatus(projectHelmChart *v1alpha1.

// getNoTargetNamespacesStatus returns the status on seeing that a ProjectHelmChart's projectNamespaceSelector (or
// the Project Registration Namespace's namespaceSelector) targets no namespaces
func (h *handler) getNoTargetNamespacesStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getNoTargetNamespacesStatus(_ *v1alpha1.ProjectHelmChart, _ v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
return v1alpha1.ProjectHelmChartStatus{
Status: "NoTargetProjectNamespaces",
StatusMessage: "There are no project namespaces to deploy a ProjectHelmChart.",
}
}

// getValuesParseErrorStatus returns the status on encountering an error with parsing the provided contents of spec.values on the ProjectHelmChart
func (h *handler) getValuesParseErrorStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus, err error) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getValuesParseErrorStatus(_ *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus, err error) v1alpha1.ProjectHelmChartStatus {
// retain existing status if possible
projectHelmChartStatus.Status = "UnableToParseValues"
projectHelmChartStatus.StatusMessage = fmt.Sprintf("Unable to convert provided spec.values into valid configuration of ProjectHelmChart: %s", err)
Expand All @@ -52,7 +52,7 @@ func (h *handler) getValuesParseErrorStatus(projectHelmChart *v1alpha1.ProjectHe
// getWaitingForDashboardValuesStatus returns the transitionary status that occurs after deploying a Helm chart but before a dashboard configmap is created
// If a ProjectHelmChart is stuck in this status, it is likely either an error on the Operator for not creating this ConfigMap or there might be an issue
// with the underlying Job ran by the child HelmChart resource created on this ProjectHelmChart's behalf
func (h *handler) getWaitingForDashboardValuesStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getWaitingForDashboardValuesStatus(_ *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
// retain existing status
projectHelmChartStatus.Status = "WaitingForDashboardValues"
projectHelmChartStatus.StatusMessage = "Waiting for status.dashboardValues content to be provided by the deployed Helm release, but HelmChart and HelmRelease should be deployed."
Expand All @@ -61,7 +61,7 @@ func (h *handler) getWaitingForDashboardValuesStatus(projectHelmChart *v1alpha1.
}

// getDeployedStatus returns the status that indicates the ProjectHelmChart is successfully deployed
func (h *handler) getDeployedStatus(projectHelmChart *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
func (h *handler) getDeployedStatus(_ *v1alpha1.ProjectHelmChart, projectHelmChartStatus v1alpha1.ProjectHelmChartStatus) v1alpha1.ProjectHelmChartStatus {
// retain existing status
projectHelmChartStatus.Status = "Deployed"
projectHelmChartStatus.StatusMessage = "ProjectHelmChart has been successfully deployed!"
Expand Down

0 comments on commit f313157

Please sign in to comment.