Skip to content

Commit

Permalink
sync dropdown border color bug, checkbox actions re-disable buttons, …
Browse files Browse the repository at this point in the history
…add img repo sync test
  • Loading branch information
joshri committed Jul 14, 2023
1 parent 526c237 commit 71c7056
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 117 deletions.
68 changes: 55 additions & 13 deletions core/server/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
Expand Down Expand Up @@ -48,16 +49,19 @@ func TestSync(t *testing.T) {
helmRepo := makeHelmRepo(name, *ns)
hr := makeHelmRelease(name, *ns, helmRepo, chart)

ir := makeImageRepository(name, *ns)

g.Expect(k.Create(ctx, gitRepo)).Should(Succeed())
g.Expect(k.Create(ctx, kust)).Should(Succeed())
g.Expect(k.Create(ctx, chart)).Should(Succeed())
g.Expect(k.Create(ctx, helmRepo)).Should(Succeed())
g.Expect(k.Create(ctx, hr)).Should(Succeed())
g.Expect(k.Create(ctx, ir)).Should(Succeed())

tests := []struct {
name string
msg *pb.SyncFluxObjectRequest
automation fluxsync.Automation
automation fluxsync.Reconcilable
source fluxsync.Reconcilable
}{{
name: "kustomization no source",
Expand Down Expand Up @@ -93,18 +97,32 @@ func TestSync(t *testing.T) {
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
},
{
name: "multiple objects",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}, {ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}},
WithSource: true,
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
}}
}, {
name: "image repo no source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: imagev1_reflect.ImageRepositoryKind}},
},
automation: fluxsync.ImageRepositoryAdapter{ImageRepository: ir},
}, {
name: "image repo with source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: imagev1_reflect.ImageRepositoryKind}},
},
automation: fluxsync.ImageRepositoryAdapter{ImageRepository: ir},
source: fluxsync.NewReconcileable(gitRepo),
}, {
name: "multiple objects",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}, {ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}},
WithSource: true,
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
}}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -203,6 +221,15 @@ func simulateReconcile(ctx context.Context, k client.Client, name types.Namespac

obj.Status.SetLastHandledReconcileRequest(time.Now().Format(time.RFC3339Nano))

return k.Status().Update(ctx, obj)

case *imagev1_reflect.ImageRepository:
if err := k.Get(ctx, name, obj); err != nil {
return err
}

obj.Status.SetLastHandledReconcileRequest(time.Now().Format(time.RFC3339Nano))

return k.Status().Update(ctx, obj)
}

Expand Down Expand Up @@ -331,3 +358,18 @@ func makeHelmRelease(name string, ns corev1.Namespace, repo *sourcev1.HelmReposi
},
}
}

func makeImageRepository(name string, ns corev1.Namespace) *imagev1_reflect.ImageRepository {
return &imagev1_reflect.ImageRepository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns.Name,
},
Spec: imagev1_reflect.ImageRepositorySpec{},
Status: imagev1_reflect.ImageRepositoryStatus{
ReconcileRequestStatus: meta.ReconcileRequestStatus{
LastHandledReconcileAt: time.Now().Format(time.RFC3339Nano),
},
},
}
}
4 changes: 1 addition & 3 deletions pkg/kube/kubehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
automation1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
reflectorv1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta1"
kustomizev2 "github.com/fluxcd/kustomize-controller/api/v1beta2"
notificationv2 "github.com/fluxcd/notification-controller/api/v1beta1"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
Expand All @@ -38,7 +37,6 @@ func CreateScheme() (*apiruntime.Scheme, error) {
rbacv1.AddToScheme,
authv1.AddToScheme,
notificationv2.AddToScheme,
reflectorv1.AddToScheme,
automation1.AddToScheme,
pacv2beta2.AddToScheme,
imagev1_reflect.AddToScheme,
Expand Down
33 changes: 5 additions & 28 deletions ui/components/CheckboxActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,49 +79,26 @@ const DefaultSuspend: React.FC<{
);
};

export type Action = {
component: React.FC;
additionalProps?: { [key: string]: any };
};

type Props = {
className?: string;
checked?: string[];
rows?: any[];
actions?: Action[];
};

function CheckboxActions({
className,
checked = [],
rows = [],
actions,
}: Props) {
function CheckboxActions({ className, checked = [], rows = [] }: Props) {
const [reqObjects, setReqObjects] = React.useState([]);
const hasChecked = checked.length > 0;

React.useEffect(() => {
if (hasChecked && rows.length) setReqObjects(makeObjects(checked, rows));
else setReqObjects([]);
}, [checked, rows]);

const defaultActions = [
{ component: DefaultSync },
{ component: DefaultSuspend, additionalProps: { suspend: true } },
{ component: DefaultSuspend, additionalProps: { suspend: false } },
];
const hasActions = actions || defaultActions;

return (
<Flex start align className={className} gap="8">
{hasActions.map((action: Action) => {
const elementProps: any = {
...action.additionalProps,
reqObjects: reqObjects,
};
return React.createElement(action.component, {
...elementProps,
});
})}
<DefaultSync reqObjects={reqObjects} />
<DefaultSuspend reqObjects={reqObjects} suspend={true} />
<DefaultSuspend reqObjects={reqObjects} suspend={false} />
</Flex>
);
}
Expand Down
9 changes: 0 additions & 9 deletions ui/components/ImageAutomation/ImageAutomationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ const ImageAutomationDetails = ({
<Spacer margin="xs" />
<PageStatus conditions={conditions} suspended={suspended} />
<Spacer margin="xs" />
{/* ImageUpdateAutomation sync is not supported yet and it'll be added in future PR */}
{/* <SyncActions
name={name}
namespace={namespace}
clusterName={clusterName}
kind={kind}
/>
<Spacer margin="xs" /> */}

<SubRouterTabs rootPath={`${rootPath}/details`}>
<RouterTab name="Details" path={`${rootPath}/details`}>
<>
Expand Down
63 changes: 0 additions & 63 deletions ui/components/ImageAutomation/SyncActions.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion ui/components/SyncButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ type Props = {

export const ArrowDropDown = styled(IconButton)`
&.MuiButton-outlined {
border-color: ${(props) => props.theme.colors.grayToPrimary};
//2px = MUI radius
border-radius: 0 2px 2px 0;
}
&.MuiButton-outlinedPrimary {
border-color: ${(props) => props.theme.colors.neutral20};
}
&.MuiButton-root {
min-width: 0;
height: 32px;
Expand Down Expand Up @@ -60,6 +62,7 @@ function SyncButton({
arrowDropDown = (
<ArrowDropDown
variant="outlined"
color="primary"
onClick={() => setOpen(!open)}
disabled={disabled}
>
Expand Down

0 comments on commit 71c7056

Please sign in to comment.