Skip to content

Commit

Permalink
Changed Get to List using the helm chart name instead of the object name
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewuolle committed Aug 28, 2024
1 parent 2f0083f commit e95147a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ COPY internal/ internal/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -gcflags=all="-N -l" -ldflags="${LD_FLAGS}" -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ lint-chart-%:
package-chart-%: $(CHARTS_PACKAGE_DIR) lint-chart-%
$(HELM) package --destination $(CHARTS_PACKAGE_DIR) $(TEMPLATES_DIR)/$*

LD_FLAGS = -X github.com/Mirantis/hmc/internal/build.Version=$(VERSION)
LD_FLAGS?= -s -w
LD_FLAGS += -X github.com/Mirantis/hmc/internal/build.Version=$(VERSION)
LD_FLAGS += -X github.com/Mirantis/hmc/internal/telemetry.segmentToken=$(SEGMENT_TOKEN)

.PHONY: build
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/deployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
const (
DeploymentFinalizer = "hmc.mirantis.com/deployment"

FluxHelmChartNameKey = "helm.toolkit.fluxcd.io/name"
HMCManagedLabelKey = "hmc.mirantis.com/managed"
HMCManagedLabelValue = "true"
)
Expand Down
8 changes: 4 additions & 4 deletions config/dev/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apiVersion: hmc.mirantis.com/v1alpha1
kind: Deployment
metadata:
name: tbone-aws-dev
name: aws-dev
spec:
template: aws-standalone-cp
config:
region: us-west-1
region: us-east-2
publicIP: true
controlPlaneNumber: 1
workersNumber: 1
controlPlane:
amiID: ami-0e99d1e59ff320ab2
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
worker:
amiID: ami-0e99d1e59ff320ab2
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
13 changes: 9 additions & 4 deletions internal/controller/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"time"

"k8s.io/apimachinery/pkg/labels"

hcv2 "github.com/fluxcd/helm-controller/api/v2"
fluxmeta "github.com/fluxcd/pkg/apis/meta"
fluxconditions "github.com/fluxcd/pkg/runtime/conditions"
Expand Down Expand Up @@ -96,17 +98,20 @@ func (r *DeploymentReconciler) setStatusFromClusterStatus(ctx context.Context, d
Resource: "clusters",
}

list, err := dc.Resource(resourceId).Namespace(deployment.Namespace).Get(ctx, deployment.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
l.Info("Cluster not found, ignoring since object must be deleted or not yet created")
list, err := dc.Resource(resourceId).Namespace(deployment.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{hmc.FluxHelmChartNameKey: deployment.Name}).String(),
})

if apierrors.IsNotFound(err) || len(list.Items) == 0 {
l.Info("Clusters not found, ignoring since object must be deleted or not yet created")
return true, nil
}

if err != nil {
return true, fmt.Errorf("failed to get cluster information for deployment %s in namespace: %s: %w",
deployment.Namespace, deployment.Name, err)
}
conditions, found, err := unstructured.NestedSlice(list.Object, "status", "conditions")
conditions, found, err := unstructured.NestedSlice(list.Items[0].Object, "status", "conditions")
if err != nil {
return true, fmt.Errorf("failed to get cluster information for deployment %s in namespace: %s: %w",
deployment.Namespace, deployment.Name, err)
Expand Down
4 changes: 2 additions & 2 deletions templates/hmc/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ spec:
readOnly: true
{{- end }}
securityContext:
runAsNonRoot: false
runAsNonRoot: true
serviceAccountName: {{ include "hmc.fullname" . }}-controller-manager
terminationGracePeriodSeconds: 6000
terminationGracePeriodSeconds: 10
{{- if .Values.admissionWebhook.enabled }}
volumes:
- name: cert
Expand Down

0 comments on commit e95147a

Please sign in to comment.