Skip to content

Commit

Permalink
Created new job that uses a label from a forked PR to build an image …
Browse files Browse the repository at this point in the history
…for the Quay.io Kuadrant Operator Registry

Added sign-off

Signed-off-by: dlaw4608 <dlawton@redhat.com>
  • Loading branch information
maksymvavilov authored and dlaw4608 committed Aug 12, 2024
1 parent 661b677 commit 96b0fcc
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 175 deletions.
119 changes: 53 additions & 66 deletions .github/workflows/build-images-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,27 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.OPERATOR_NAME }}
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
dockerfiles: |
./Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to container registry
uses: docker/login-action@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
registry: ${{ env.IMG_REGISTRY_HOST }}
- name: Build and Push Image
id: build-image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}:${{ env.IMG_TAGS }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
run: echo "Image pushed to ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}:${{ env.IMG_TAGS }}"

build-bundle:
needs: build
Expand All @@ -123,10 +119,6 @@ jobs:
id: go
- name: Check out code
uses: actions/checkout@v3
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Run make bundle
id: make-bundle
run: |
Expand All @@ -138,27 +130,27 @@ jobs:
WASM_SHIM_VERSION=${{ inputs.wasmShimVersion }} \
REPLACES_VERSION=${{ inputs.replacesVersion }} \
CHANNELS=${{ inputs.channels }}
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to container registry
uses: docker/login-action@v2
with:
image: ${{ env.OPERATOR_NAME }}-bundle
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
dockerfiles: |
./bundle.Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
registry: ${{ env.IMG_REGISTRY_HOST }}
- name: Build and Push Bundle Image
id: build-bundle-image
uses: docker/build-push-action@v5
with:
context: .
file: ./bundle.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-bundle:${{ env.IMG_TAGS }}
- name: Print Bundle Image URL
run: echo "Bundle image pushed to ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-bundle:${{ env.IMG_TAGS }}"

build-catalog:
name: Build Catalog
Expand All @@ -182,29 +174,24 @@ jobs:
WASM_SHIM_VERSION=${{ inputs.wasmShimVersion }} \
REPLACES_VERSION=${{ inputs.replacesVersion }} \
CHANNELS=${{ inputs.channels }}
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to container registry
uses: docker/login-action@v2
with:
image: ${{ env.OPERATOR_NAME }}-catalog
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
context: ./catalog
dockerfiles: |
./catalog/kuadrant-operator-catalog.Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}
username: ${{ secrets.IMG_REGISTRY_USERNAME }}
password: ${{ secrets.IMG_REGISTRY_TOKEN }}
- name: Print Image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
registry: ${{ env.IMG_REGISTRY_HOST }}
- name: Build and Push Catalog Image
id: build-catalog-image
uses: docker/build-push-action@v5
with:
context: ./catalog
file: ./catalog/kuadrant-operator-catalog.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-catalog:${{ env.IMG_TAGS }}
- name: Print Catalog Image URL
run: echo "Catalog image pushed to ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ env.OPERATOR_NAME }}-catalog:${{ env.IMG_TAGS }}"
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM --platform=$BUILDPLATFORM golang:1.22 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -15,8 +15,11 @@ COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

# Set environment variables for cross-compilation
ARG TARGETARCH

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -a -o manager 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
69 changes: 37 additions & 32 deletions controllers/dnspolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"errors"
"fmt"
"slices"
"strings"

Expand All @@ -34,6 +35,7 @@ import (

"github.com/kuadrant/kuadrant-operator/api/v1alpha1"
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
)

var NegativePolarityConditions []string
Expand Down Expand Up @@ -102,55 +104,58 @@ func (r *DNSPolicyReconciler) calculateStatus(ctx context.Context, dnsPolicy *v1
}

recordsList := &kuadrantdnsv1alpha1.DNSRecordList{}
controlledRecords := &kuadrantdnsv1alpha1.DNSRecordList{}

var enforcedCondition *metav1.Condition
if err := r.Client().List(ctx, recordsList); err != nil {
enforcedCondition = kuadrant.EnforcedCondition(dnsPolicy, kuadrant.NewErrUnknown(dnsPolicy.Kind(), err), false)
} else {
// leave only records controlled by the policy
recordsList.Items = utils.Filter(recordsList.Items, func(record kuadrantdnsv1alpha1.DNSRecord) bool {
for _, reference := range record.GetOwnerReferences() {
if reference.Controller != nil && *reference.Controller && reference.Name == dnsPolicy.Name && reference.UID == dnsPolicy.UID {
return true

Check warning on line 116 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L113-L116

Added lines #L113 - L116 were not covered by tests
}
}
return false

Check warning on line 119 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L119

Added line #L119 was not covered by tests
})

enforcedCondition = r.enforcedCondition(recordsList, dnsPolicy)
}

meta.SetStatusCondition(&newStatus.Conditions, *enforcedCondition)

for _, record := range recordsList.Items {
for _, reference := range record.GetOwnerReferences() {
if reference.Controller != nil && *reference.Controller && reference.Name == dnsPolicy.Name && reference.UID == dnsPolicy.UID {
controlledRecords.Items = append(controlledRecords.Items, record)
}
}
}

propagateRecordConditions(controlledRecords, newStatus)
propagateRecordConditions(recordsList, newStatus)

Check warning on line 126 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L126

Added line #L126 was not covered by tests

return newStatus
}

func (r *DNSPolicyReconciler) enforcedCondition(recordsList *kuadrantdnsv1alpha1.DNSRecordList, dnsPolicy *v1alpha1.DNSPolicy) *metav1.Condition {
var controlled bool
for _, record := range recordsList.Items {
// check that DNS record is controller by this policy
for _, reference := range record.GetOwnerReferences() {
if reference.Controller != nil && *reference.Controller && reference.Name == dnsPolicy.Name && reference.UID == dnsPolicy.UID {
controlled = true
// if at least one record not ready the policy is not enforced
for _, condition := range record.Status.Conditions {
if condition.Type == string(kuadrantdnsv1alpha1.ConditionTypeReady) && condition.Status == metav1.ConditionFalse {
return kuadrant.EnforcedCondition(dnsPolicy, nil, false)
}
}
break
}
}
// there are no controlled DNS records present
if len(recordsList.Items) == 0 {
return kuadrant.EnforcedCondition(dnsPolicy, kuadrant.NewErrUnknown(dnsPolicy.Kind(), errors.New("policy is not enforced on any DNSRecord: no routes attached for listeners")), false)

Check warning on line 134 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L133-L134

Added lines #L133 - L134 were not covered by tests
}

// filter not ready records
notReadyRecords := utils.Filter(recordsList.Items, func(record kuadrantdnsv1alpha1.DNSRecord) bool {
return meta.IsStatusConditionFalse(record.Status.Conditions, string(kuadrantdnsv1alpha1.ConditionTypeReady))
})

Check warning on line 140 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L138-L140

Added lines #L138 - L140 were not covered by tests

// none of the records are ready
if len(notReadyRecords) == len(recordsList.Items) {
return kuadrant.EnforcedCondition(dnsPolicy, kuadrant.NewErrUnknown(dnsPolicy.Kind(), errors.New("policy is not enforced on any DNSRecord: not a single DNSRecord is ready")), false)

Check warning on line 144 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L143-L144

Added lines #L143 - L144 were not covered by tests
}

// at least one DNS record is controlled by the policy
// and all controlled records are accepted
if controlled {
return kuadrant.EnforcedCondition(dnsPolicy, nil, true)
// some of the records are not ready
if len(notReadyRecords) > 0 {
additionalMessage := ". Not ready DNSRecords are: "
for _, record := range notReadyRecords {
additionalMessage += fmt.Sprintf("%s ", record.Name)

Check warning on line 151 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L148-L151

Added lines #L148 - L151 were not covered by tests
}
cond := kuadrant.EnforcedCondition(dnsPolicy, nil, false)
cond.Message += additionalMessage
return cond

Check warning on line 155 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L153-L155

Added lines #L153 - L155 were not covered by tests
}
// there are no controlled DNS records present
return kuadrant.EnforcedCondition(dnsPolicy, kuadrant.NewErrUnknown(dnsPolicy.Kind(), errors.New("policy is not enforced on any dns record: no routes attached for listeners")), false)
// all records are ready
return kuadrant.EnforcedCondition(dnsPolicy, nil, true)

Check warning on line 158 in controllers/dnspolicy_status.go

View check run for this annotation

Codecov / codecov/patch

controllers/dnspolicy_status.go#L158

Added line #L158 was not covered by tests
}

func propagateRecordConditions(records *kuadrantdnsv1alpha1.DNSRecordList, policyStatus *v1alpha1.DNSPolicyStatus) {
Expand Down
16 changes: 0 additions & 16 deletions tests/common/dnspolicy/dnspolicy_controller_single_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/kuadrant/kuadrant-operator/api/v1alpha1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/tests"
)
Expand Down Expand Up @@ -170,21 +169,6 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
})

It("should create dns records", func(ctx SpecContext) {

Eventually(func(g Gomega, ctx context.Context) {

g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(dnsPolicy), dnsPolicy)).To(Succeed())
g.Expect(dnsPolicy.Status.Conditions).To(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(string(kuadrant.PolicyConditionEnforced)),
"Status": Equal(metav1.ConditionTrue),
"Reason": Equal(string(kuadrant.PolicyReasonEnforced)),
"Message": Equal("DNSPolicy has been partially enforced"),
})),
)

}, tests.TimeoutMedium, tests.RetryIntervalMedium, ctx).Should(Succeed())

Eventually(func(g Gomega, ctx context.Context) {
recordList := &kuadrantdnsv1alpha1.DNSRecordList{}
err := k8sClient.List(ctx, recordList, &client.ListOptions{Namespace: testNamespace})
Expand Down
Loading

0 comments on commit 96b0fcc

Please sign in to comment.