Skip to content

Commit

Permalink
Merge branch 'main' into notify_for_new_profile_versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jan 25, 2022
2 parents 3a0752f + 1805f68 commit 35934a6
Show file tree
Hide file tree
Showing 16 changed files with 604 additions and 110 deletions.
12 changes: 12 additions & 0 deletions manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ metadata:
kind: RoleBinding
metadata:
name: read-resources`))

By("containing a Cluster Role manifest")
Expect(manifests).To(ContainSubstring(`
kind: ClusterRole
metadata:
name: wego-helm-watcher-role`))

By("containing a Cluster Role Binding manifest")
Expect(manifests).To(ContainSubstring(`
kind: ClusterRoleBinding
metadata:
name: wego-helm-watcher-rolebinding`))
})
})
})
31 changes: 31 additions & 0 deletions manifests/wego-app/helm_watcher_role.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: wego-helm-watcher-role
rules:
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmrepositories
verbs:
- get
- list
- watch
- patch
- update
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmrepositories/finalizers
verbs:
- create
- delete
- get
- patch
- update
- apiGroups:
- source.toolkit.fluxcd.io
resources:
- helmrepositories/status
verbs:
- get
12 changes: 12 additions & 0 deletions manifests/wego-app/helm_watcher_role_binding.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: wego-helm-watcher-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: wego-helm-watcher-role
subjects:
- kind: ServiceAccount
name: wego-app-service-account
namespace: {{ .Namespace }}
2 changes: 1 addition & 1 deletion pkg/helm/watcher/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewWatcher(opts Options) (*Watcher, error) {

func (w *Watcher) StartWatcher() error {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zap.Options{
Development: true,
Development: false,
})))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down
4 changes: 3 additions & 1 deletion pkg/services/auth/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ var _ = Describe("Github Device Flow", func() {
Expect(cliOutput.String()).To(ContainSubstring(userCode))
Expect(cliOutput.String()).To(ContainSubstring(verificationUri))
})
Describe("pollAuthStatus", func() {

// These auth flow tests are failing intermittently, so bypass them for now
XDescribe("pollAuthStatus", func() {
It("retries after a slow_down response from github", func() {
rt := newMockRoundTripper(3, token)
client.Transport = &testServerTransport{testServeUrl: ts.URL, roundTripper: rt}
Expand Down
3 changes: 2 additions & 1 deletion pkg/services/gitops/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"fmt"

apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/weaveworks/weave-gitops/cmd/gitops/version"
"github.com/weaveworks/weave-gitops/manifests"
"github.com/weaveworks/weave-gitops/pkg/kube"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)

type UninstallParams struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/services/gitops/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

wego "github.com/weaveworks/weave-gitops/api/v1alpha1"
"github.com/weaveworks/weave-gitops/cmd/gitops/version"
"github.com/weaveworks/weave-gitops/manifests"
Expand Down Expand Up @@ -60,7 +61,7 @@ func checkAppCRDUninstallFailure() {
Expect(err).To(MatchError(gitops.UninstallError{}))
Expect(kubeClient.GetClusterStatusCallCount()).To(Equal(1))
Expect(fluxClient.UninstallCallCount()).To(Equal(1))
Expect(kubeClient.DeleteCallCount()).To(Equal(6))
Expect(kubeClient.DeleteCallCount()).To(Equal(8))

namespace, dryRun := fluxClient.UninstallArgsForCall(0)
Expect(namespace).To(Equal(wego.DefaultNamespace))
Expand Down
39 changes: 29 additions & 10 deletions test/acceptance/test/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ import (
"fmt"
"net/http"
"net/url"
"path/filepath"
"time"

sourcev1beta1 "github.com/fluxcd/source-controller/api/v1beta1"
pb "github.com/weaveworks/weave-gitops/pkg/api/profiles"
"github.com/weaveworks/weave-gitops/pkg/gitproviders"
"github.com/weaveworks/weave-gitops/pkg/kube"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"path/filepath"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"sigs.k8s.io/controller-runtime/pkg/client"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pb "github.com/weaveworks/weave-gitops/pkg/api/profiles"
"github.com/weaveworks/weave-gitops/pkg/gitproviders"
"github.com/weaveworks/weave-gitops/pkg/kube"
)

var _ = PDescribe("Weave GitOps Profiles API", func() {
Expand Down Expand Up @@ -104,6 +103,26 @@ podinfo Podinfo Helm chart for Kubernetes 6.0.0,6.0.1
Expect(err).NotTo(HaveOccurred())
Expect(string(values)).To(ContainSubstring("# Default values for podinfo"))
})
It("profiles are installed into a different namespace", func() {
By("Installing the Profiles API and setting up the profile helm repository")
appRepoRemoteURL = "git@github.com:" + githubOrg + "/" + tip.appRepoName + ".git"
installAndVerifyWego(namespace, appRepoRemoteURL)
By("Creating a new namespace")
namespaceCreatedMsg := runCommandAndReturnSessionOutput("kubectl create ns other")
Eventually(namespaceCreatedMsg).Should(gbytes.Say("namespace/other created"))
By("And installing a helmrepositroy into that namespace")
deployProfilesHelmRepository(kClient, "other")
time.Sleep(time.Second * 20)

By("Getting a list of profiles should still work")
_, statusCode, err := kubernetesDoRequest(namespace, wegoService, wegoPort, "/v1/profiles", clientSet)
Expect(err).NotTo(HaveOccurred())
Expect(statusCode).To(Equal(http.StatusOK))

By("There should be no errors in the wego app log from the helm cache")
log := runCommandAndReturnSessionOutput("kubectl logs ")
Eventually(log).ShouldNot(gbytes.Say("\\\"other\\\" is forbidden"))
})
})

func buildKubernetesClients() (*kubernetes.Clientset, client.Client) {
Expand Down
1 change: 0 additions & 1 deletion ui/components/CommitsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function CommitsTable({
<div className={className}>
<DataTable
sortFields={["date"]}
reverseSort
fields={[
{
label: "SHA",
Expand Down
69 changes: 63 additions & 6 deletions ui/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
import _ from "lodash";
import * as React from "react";
import styled from "styled-components";
import Button from "./Button";
import Flex from "./Flex";
import Icon, { IconType } from "./Icon";
import Spacer from "./Spacer";
import Text from "./Text";

/** DataTable Properties */
Expand All @@ -24,8 +28,6 @@ export interface Props {
rows: any[];
/** A list of strings representing the sortable columns of the table, passed into lodash's `_.sortBy`. */
sortFields: string[];
/** Indicates whether to reverse the sorted array. */
reverseSort?: boolean;
/** an optional list of string widths for each field/column. */
widths?: string[];
}
Expand All @@ -37,21 +39,68 @@ const EmptyRow = styled(TableRow)<{ colSpan: number }>`
}
`;

const TableButton = styled(Button)`
&.MuiButton-root {
padding: 0;
margin: 0;
text-transform: none;
}
&.MuiButton-text {
color: ${(props) => props.theme.colors.neutral30};
min-width: 0px;
}
&.arrow {
min-width: 0px;
}
&.selected {
color: ${(props) => props.theme.colors.neutral40};
}
`;

/** Form DataTable */
function UnstyledDataTable({
className,
fields,
rows,
sortFields,
reverseSort,
widths,
}: Props) {
const sorted = _.sortBy(rows, sortFields);
const [sort, setSort] = React.useState(sortFields[0]);
const [reverseSort, setReverseSort] = React.useState(false);
const sorted = _.sortBy(rows, sort);

if (reverseSort) {
sorted.reverse();
}

type labelProps = { label: string };
function SortableLabel({ label }: labelProps) {
return (
<Flex align start>
<TableButton
color="inherit"
variant="text"
onClick={() => {
setReverseSort(sort === label.toLowerCase() ? !reverseSort : false);
setSort(label.toLowerCase());
}}
>
<h2>{label}</h2>
</TableButton>
<Spacer padding="xxs" />
{sort === label.toLowerCase() ? (
<Icon
type={IconType.ArrowUpwardIcon}
size="base"
className={reverseSort ? "upward" : "downward"}
/>
) : (
<div style={{ width: "16px" }} />
)}
</Flex>
);
}

const r = _.map(sorted, (r, i) => (
<TableRow key={i}>
{_.map(fields, (f, i) => (
Expand All @@ -70,7 +119,11 @@ function UnstyledDataTable({
<TableRow>
{_.map(fields, (f, i) => (
<TableCell style={widths && { width: widths[i] }} key={f.label}>
{f.label}
{sortFields.includes(f.label.toLowerCase()) ? (
<SortableLabel label={f.label} />
) : (
<h2 className="thead">{f.label}</h2>
)}
</TableCell>
))}
</TableRow>
Expand All @@ -93,7 +146,11 @@ function UnstyledDataTable({
}

export const DataTable = styled(UnstyledDataTable)`
.MuiTableCell-head {
h2 {
margin: 0px;
}
.thead {
color: ${(props) => props.theme.colors.neutral30};
font-weight: 800;
}
`;
Expand Down
13 changes: 9 additions & 4 deletions ui/components/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import AccountCircleIcon from "@material-ui/icons/AccountCircle";
import AddIcon from "@material-ui/icons/Add";
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
import ArrowUpwardIcon from "@material-ui/icons/ArrowUpward";
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
import DeleteIcon from "@material-ui/icons/Delete";
import NavigateNextIcon from "@material-ui/icons/NavigateNext";
import SaveAltIcon from "@material-ui/icons/SaveAlt";
import ErrorIcon from "@material-ui/icons/Error";
import HourglassFullIcon from "@material-ui/icons/HourglassFull";
import LaunchIcon from "@material-ui/icons/Launch";
import NavigateNextIcon from "@material-ui/icons/NavigateNext";
import SaveAltIcon from "@material-ui/icons/SaveAlt";
import * as React from "react";
import styled from "styled-components";
import { colors, spacing } from "../typedefs/styled";
Expand Down Expand Up @@ -95,7 +95,12 @@ export default styled(Icon)`
height: ${(props) => props.theme.spacing[props.size as any]};
width: ${(props) => props.theme.spacing[props.size as any]};
}
&.downward {
transform: rotate(180deg);
}
&.upward {
transform: initial;
}
${Text} {
margin-left: 4px;
color: ${(props) => props.theme.colors[props.color as any]};
Expand Down
Loading

0 comments on commit 35934a6

Please sign in to comment.