From 0acd26f2a314c7d70c46b1021dfd1c6a210f7a7c Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 1 Nov 2023 10:19:54 -0500 Subject: [PATCH 1/6] Remove hard-coded prefix on container group name We have project names to disambiguate these on the SCE side and namespaces on the K8s side. Signed-off-by: Dean Troyer --- internal/utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 512e47b..3b8668d 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -49,7 +49,7 @@ func GetPodName(nameSpace, containerGroup string, pod *corev1.Pod) string { if nameSpace == "" && containerGroup == "" && pod.Spec.Containers[0].Name != "" { return pod.Spec.Containers[0].Name } - return "salad-cloud-" + nameSpace + "-" + containerGroup + return nameSpace + "-" + containerGroup } func GetPodPhaseFromContainerGroupState(containerGroupState saladclient.ContainerGroupState) corev1.PodPhase { From fa98b0c26026d7e914e2a59179f2762e0f8f653f Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 1 Nov 2023 15:16:57 -0500 Subject: [PATCH 2/6] Simulate creating a ProblemDetails from unknown errors from the server utils.GetResponseBody() can return an unknown_error type if the response Body fails to decode as JSON. This will bubble the remote error rather than log a "failed to decode" message. Signed-off-by: Dean Troyer --- internal/provider/provider.go | 11 ++++++----- internal/utils/utils.go | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ddb77e6..11a7269 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -229,8 +229,8 @@ func (p *SaladCloudProvider) DeletePod(ctx context.Context, pod *corev1.Pod) err } func (p *SaladCloudProvider) GetPod(ctx context.Context, namespace string, name string) (*corev1.Pod, error) { - - resp, r, err := saladclient.NewAPIClient(saladclient.NewConfiguration()).ContainerGroupsAPI.GetContainerGroup(p.contextWithAuth(), p.inputVars.OrganizationName, p.inputVars.ProjectName, utils.GetPodName(namespace, name, nil)).Execute() + podname := utils.GetPodName(namespace, name, nil) + resp, r, err := saladclient.NewAPIClient(saladclient.NewConfiguration()).ContainerGroupsAPI.GetContainerGroup(p.contextWithAuth(), p.inputVars.OrganizationName, p.inputVars.ProjectName, podname).Execute() if err != nil { // Get response body for error info pd, err := utils.GetResponseBody(r) @@ -240,7 +240,7 @@ func (p *SaladCloudProvider) GetPod(ctx context.Context, namespace string, name } if r.StatusCode == 404 { - p.logger.Warnf("`ContainerGroupsAPI.GetPod`: %s not found", name) + p.logger.Warnf("`ContainerGroupsAPI.GetPod`: %s not found", podname) } else { p.logger.Errorf("`ContainerGroupsAPI.GetPod`: Error: %+v", *pd) } @@ -287,7 +287,8 @@ func (p *SaladCloudProvider) GetPodStatus(ctx context.Context, namespace string, _, span := trace.StartSpan(ctx, "GetPodStatus") defer span.End() - containerGroup, response, err := p.apiClient.ContainerGroupsAPI.GetContainerGroup(p.contextWithAuth(), p.inputVars.OrganizationName, p.inputVars.ProjectName, utils.GetPodName(namespace, name, nil)).Execute() + podname := utils.GetPodName(namespace, name, nil) + containerGroup, response, err := p.apiClient.ContainerGroupsAPI.GetContainerGroup(p.contextWithAuth(), p.inputVars.OrganizationName, p.inputVars.ProjectName, podname).Execute() if err != nil { // Get response body for error info pd, err := utils.GetResponseBody(response) @@ -298,7 +299,7 @@ func (p *SaladCloudProvider) GetPodStatus(ctx context.Context, namespace string, if response.StatusCode == 404 { p.logger.WithField("namespace", namespace). - WithField("name", name). + WithField("name", podname). Warnf("Not Found") } else { p.logger.WithField("namespace", namespace). diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 3b8668d..7f922d1 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -2,7 +2,6 @@ package utils import ( "bytes" - "fmt" "io" "net/http" @@ -89,7 +88,12 @@ func GetResponseBody(response *http.Response) (*saladclient.ProblemDetails, erro pd := saladclient.NewNullableProblemDetails(nil) err := pd.UnmarshalJSON(body) if err != nil { - return nil, fmt.Errorf("Error decoding response body: %s", response.Body) + // Can't decode ProblemDetails, just make one and return the string + npd := saladclient.NewProblemDetails() + npd.SetType("unknown_error") + npd.SetTitle("Error decoding response body") + npd.SetDetail(string(body)) + pd.Set(npd) } return pd.Get(), nil } From 80b5070e91724843dd6aad696b9fd4ce79278f5f Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 13 Nov 2023 10:27:41 -0600 Subject: [PATCH 3/6] Updates to demo yaml Signed-off-by: Dean Troyer --- demo/qr.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/demo/qr.yaml b/demo/qr.yaml index f0a75d8..5fcba37 100644 --- a/demo/qr.yaml +++ b/demo/qr.yaml @@ -6,7 +6,7 @@ metadata: name: qr-code namespace: saladcloud-demo spec: - replicas: 2 + replicas: 1 selector: matchLabels: app: qr-code-demo @@ -26,9 +26,12 @@ spec: - image: saladtechnologies/stable-fast-qr-code:latest-baked name: qr-code resources: + requests: + cpu: 2 + memory: 8Gi limits: cpu: 2 - memory: 8192 + memory: 8Gi env: - name: HOST value: "*" From 5d79d4a0c48565bcfc6c3d096991fa0e1bd32f78 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 8 Nov 2023 16:53:20 -0600 Subject: [PATCH 4/6] Logging bits Signed-off-by: Dean Troyer --- internal/provider/provider.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 11a7269..77711ed 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -105,7 +105,7 @@ func (p *SaladCloudProvider) NotifyPods(ctx context.Context, notifierCallback fu func (p *SaladCloudProvider) CreatePod(ctx context.Context, pod *corev1.Pod) error { ctx, span := trace.StartSpan(ctx, "CreatePod") defer span.End() - p.logger.Debug("creating a CreatePod", pod.Name) + p.logger.Debugf("CreatePod: ", pod.Name) createContainerObject := p.createContainersObject(pod) createContainerGroup := p.createContainerGroup(createContainerObject, pod) @@ -192,6 +192,7 @@ func (p *SaladCloudProvider) CreatePod(ctx context.Context, pod *corev1.Pod) err } func (p *SaladCloudProvider) UpdatePod(ctx context.Context, pod *corev1.Pod) error { + p.logger.Debugf("UpdatePod: %s: %+v", utils.GetPodName(pod.Namespace, pod.Name, pod), pod) return nil } From 0be9500902895cd3480cc5aebc1d969483ec765a Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 13 Nov 2023 10:28:07 -0600 Subject: [PATCH 5/6] provider logging Signed-off-by: Dean Troyer --- internal/provider/provider.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 77711ed..9e46852 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -105,9 +105,11 @@ func (p *SaladCloudProvider) NotifyPods(ctx context.Context, notifierCallback fu func (p *SaladCloudProvider) CreatePod(ctx context.Context, pod *corev1.Pod) error { ctx, span := trace.StartSpan(ctx, "CreatePod") defer span.End() - p.logger.Debugf("CreatePod: ", pod.Name) + p.logger.Infof("CreatePod: %s", pod.Name) createContainerObject := p.createContainersObject(pod) + p.logger.Debugf(" createContainerObject: %+v", createContainerObject) createContainerGroup := p.createContainerGroup(createContainerObject, pod) + p.logger.Debugf(" createContainerGroup: %+v", createContainerGroup[0]) _, r, err := p.apiClient. ContainerGroupsAPI.CreateContainerGroup( From 311eaa92aba00e34763c3f2e8c1b9bd4eddc148b Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 29 Nov 2023 13:28:35 -0600 Subject: [PATCH 6/6] Demo: Requests/limits are strings Signed-off-by: Dean Troyer --- demo/qr.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/qr.yaml b/demo/qr.yaml index 5fcba37..404d665 100644 --- a/demo/qr.yaml +++ b/demo/qr.yaml @@ -27,10 +27,10 @@ spec: name: qr-code resources: requests: - cpu: 2 + cpu: "2" memory: 8Gi limits: - cpu: 2 + cpu: "2" memory: 8Gi env: - name: HOST