Skip to content

Commit

Permalink
Merge branch 'master' into fix/probe-source-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriofbrito authored Oct 11, 2024
2 parents 1d351e5 + ff85c86 commit 933a71f
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 96 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Fill out the [LitmusChaos Meetings invite form](https://forms.gle/xYZyZ2gTWMqz7x

Community Blogs:

- Daniyal Rayn: [Do I need Chaos Engineering on my environment? Trust me you need it!](https://maveric-systems.com/blog/do-i-need-chaos-engineering-on-my-environment-trust-me-you-need-it/)
- LiveWyer: [LitmusChaos Showcase: Chaos Experiments in a Helm Chart Test Suite](https://livewyer.io/blog/2021/03/22/litmuschaos-showcase-chaos-experiments-in-a-helm-chart-test-suite/)
- Jessica Cherry: [Test Kubernetes cluster failures and experiments in your terminal](https://opensource.com/article/21/6/kubernetes-litmus-chaos)
- Yang Chuansheng(KubeSphere): [KubeSphere 部署 Litmus 至 Kubernetes 开启混沌实验](https://kubesphere.io/zh/blogs/litmus-kubesphere/)
Expand All @@ -138,8 +137,6 @@ Community Blogs:
- Akram Riahi(WeScale):[Chaos Engineering : Litmus sous tous les angles](https://blog.wescale.fr/2021/03/11/chaos-engineering-litmus-sous-tous-les-angles/)
- Prashanto Priyanshu(LensKart):[Lenskart’s approach to Chaos Engineering-Part 2](https://blog.lenskart.com/lenskarts-approach-to-chaos-engineering-part-2-6290e4f3a74e)
- DevsDay.ru(Russian):[LitmusChaos at Kubecon EU '21](https://devsday.ru/blog/details/40746)
- Ryan Pei(Armory): [LitmusChaos in your Spinnaker Pipeline](https://www.armory.io/blog/litmuschaos-in-your-spinnaker-pipeline/)
- David Gildeh(Zebrium): [Using Autonomous Monitoring with Litmus Chaos Engine on Kubernetes](https://www.zebrium.com/blog/using-autonomous-monitoring-with-litmus-chaos-engine-on-kubernetes)


## Adopters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

fuzz "github.com/AdaLogics/go-fuzz-headers"
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
"github.com/stretchr/testify/mock"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -47,39 +46,6 @@ func NewMockServices() *MockServices {
}
}

func FuzzProcessExperimentRunDelete(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)
targetStruct := &struct {
Query bson.D
WorkflowRunID *string
ExperimentRun dbChaosExperimentRun.ChaosExperimentRun
Workflow dbChaosExperiment.ChaosExperimentRequest
Username string
StoreStateData *store.StateData
}{}
err := fuzzConsumer.GenerateStruct(targetStruct)
if err != nil {
return
}
mockServices := NewMockServices()
mockServices.MongodbOperator.On("Update", mock.Anything, mongodb.ChaosExperimentRunsCollection, mock.Anything, mock.Anything, mock.Anything).Return(&mongo.UpdateResult{}, nil).Once()

err = mockServices.ChaosExperimentRunService.ProcessExperimentRunDelete(
context.Background(),
targetStruct.Query,
targetStruct.WorkflowRunID,
targetStruct.ExperimentRun,
targetStruct.Workflow,
targetStruct.Username,
targetStruct.StoreStateData,
)
if err != nil {
t.Errorf("ProcessExperimentRunDelete() error = %v", err)
}
})
}

func FuzzProcessExperimentRunStop(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime

err = c.chaosExperimentOperator.UpdateChaosExperiment(sessionContext, filter, update)
if err != nil {
logrus.Error("Failed to update experiment collection")
logrus.WithError(err).Error("Failed to update experiment collection")
return err
}
} else if experimentRunCount > 0 {
Expand Down Expand Up @@ -1257,7 +1257,7 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime

err = c.chaosExperimentOperator.UpdateChaosExperiment(sessionContext, filter, update)
if err != nil {
logrus.Error("Failed to update experiment collection")
logrus.WithError(err).Error("Failed to update experiment collection")
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,6 @@ func FuzzGetChartsPath(f *testing.F) {
})
}

func FuzzReadExperimentFile(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)

// Create a temporary directory
tmpDir, err := os.MkdirTemp("", "*-fuzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir) // clean up

// Ensure the filename is valid and unique
safeFilename := filepath.Clean(filepath.Base(filename))
if isInvalidFilename(safeFilename) {
safeFilename = "test.yaml"
}
filePath := filepath.Join(tmpDir, safeFilename)
content := ChaosChart{}
err = fuzzConsumer.GenerateStruct(&content)
if err != nil {
return
}

jsonContent, _ := json.Marshal(content)
err = os.WriteFile(filePath, jsonContent, 0644)
if err != nil {
t.Fatal(err)
}

_, err = ReadExperimentFile(filePath)

if err != nil && !isInvalidYAML(jsonContent) {
t.Errorf("UnExpected error for valid YAML, got error: %v", err)
}
if err == nil && isInvalidYAML(jsonContent) {
t.Errorf("Expected error for invalid YAML, got nil")
}

_, err = ReadExperimentFile("./not_exist_file.yaml")
if err == nil {
t.Errorf("Expected error for file does not exist, got nil")
}
})
}

func FuzzGetExperimentData(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)
Expand Down
3 changes: 2 additions & 1 deletion chaoscenter/graphql/server/pkg/chaoshub/ops/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/utils"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
Expand Down Expand Up @@ -284,7 +285,7 @@ func (c ChaosHubConfig) generateAuthMethod() (transport.AuthMethod, error) {
var auth transport.AuthMethod
if c.AuthType == model.AuthTypeToken {
auth = &http.BasicAuth{
Username: "litmus", // this can be anything except an empty string
Username: utils.Config.GitUsername, // must be a non-empty string or 'x-token-auth' for Bitbucket
Password: *c.Token,
}
} else if c.AuthType == model.AuthTypeBasic {
Expand Down
4 changes: 3 additions & 1 deletion chaoscenter/graphql/server/pkg/gitops/gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"
"time"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/utils"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
Expand Down Expand Up @@ -184,7 +186,7 @@ func (c GitConfig) getAuthMethod() (transport.AuthMethod, error) {

case model.AuthTypeToken:
return &http.BasicAuth{
Username: "litmus", // this can be anything except an empty string
Username: utils.Config.GitUsername, // must be a non-empty string or 'x-token-auth' for Bitbucket
Password: *c.Token,
}, nil

Expand Down
1 change: 1 addition & 0 deletions chaoscenter/graphql/server/utils/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Configuration struct {
GrpcPort string `split_words:"true" default:"8000"`
InfraCompatibleVersions string `required:"true" split_words:"true"`
DefaultHubGitURL string `required:"true" default:"https://github.com/litmuschaos/chaos-charts"`
GitUsername string `required:"true" split_words:"true" default:"litmus"`
DefaultHubBranchName string `required:"true" split_words:"true"`
CustomChaosHubPath string `split_words:"true" default:"/tmp/"`
DefaultChaosHubPath string `split_words:"true" default:"/tmp/default/"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export default function blankCanvasTemplate(

switch (infrastructureType) {
case InfrastructureType.KUBERNETES:
return kubernetesBlankCanvasTemplate(experimentName, experiment?.chaosInfrastructure?.namespace);
return kubernetesBlankCanvasTemplate(
experimentName,
experiment?.chaosInfrastructure?.namespace,
undefined,
experiment?.imageRegistry,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ const ExperimentDashboardV2Table = ({
);
case ExperimentRunStatus.QUEUED:
return (
<RunExperimentButton
buttonProps={{ disabled: true }}
<StopExperimentButton
experimentID={data.experimentID}
refetchExperiments={refetchExperiments}
infrastructureType={InfrastructureType.KUBERNETES}
/>
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const MenuCell = ({
onError: error => showError(error.message)
});

const lastExperimentRunStatus = data.recentExecutions[0]?.experimentRunStatus;
const isDeleteButtonEnabled = !data.recentExecutions.some(
execution => execution?.experimentRunStatus === ExperimentRunStatus.RUNNING
);

// <!-- confirmation dialog boxes -->
const confirmationDialogProps = {
Expand Down Expand Up @@ -108,10 +110,7 @@ export const MenuCell = ({
icon="main-trash"
text={getString('deleteExperiment')}
onClick={openDeleteDialog}
disabled={
lastExperimentRunStatus === ExperimentRunStatus.RUNNING ||
lastExperimentRunStatus === ExperimentRunStatus.QUEUED
}
disabled={isDeleteButtonEnabled == false}
permission={PermissionGroup.OWNER}
/>
</Menu>
Expand Down
27 changes: 26 additions & 1 deletion chaoscenter/web/src/views/StudioOverview/StudioOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { ChaosInfrastructureReferenceFieldProps, StudioErrorState, StudioTabs }
import experimentYamlService from 'services/experiment';
import KubernetesChaosInfrastructureReferenceFieldController from '@controllers/KubernetesChaosInfrastructureReferenceField';
import { InfrastructureType } from '@api/entities';
import { getImageRegistry } from '@api/core/ImageRegistry';
import { getScope } from '@utils';
import css from './StudioOverview.module.scss';

interface StudioOverviewViewProps {
Expand Down Expand Up @@ -52,6 +54,20 @@ export default function StudioOverviewView({

const [currentExperiment, setCurrentExperiment] = React.useState<ExperimentMetadata | undefined>();

const scope = getScope();

// Fetch the image registry data using Apollo's useQuery hook
const { data: getImageRegistryData, loading: imageRegistryLoading } = getImageRegistry({
projectID: scope.projectID,
});

const imageRegistry = getImageRegistryData?.getImageRegistry?{
name: getImageRegistryData.getImageRegistry.imageRegistryInfo.imageRegistryName,
repo: getImageRegistryData.getImageRegistry.imageRegistryInfo.imageRepoName,
secret: getImageRegistryData.getImageRegistry.imageRegistryInfo.secretName,
}
: undefined;

React.useEffect(() => {
experimentHandler?.getExperiment(experimentKey).then(experiment => {
delete experiment?.manifest;
Expand Down Expand Up @@ -85,6 +101,9 @@ export default function StudioOverviewView({
})
})}
onSubmit={values => {

values.imageRegistry = imageRegistry

if (values.chaosInfrastructure.namespace === undefined) {
delete values.chaosInfrastructure.namespace;
}
Expand Down Expand Up @@ -144,7 +163,13 @@ export default function StudioOverviewView({
text={getString('cancel')}
onClick={openDiscardDialog}
/>
<Button type="submit" intent="primary" text={getString('next')} rightIcon="chevron-right" />
<Button
type="submit"
intent="primary"
text={getString('next')}
rightIcon="chevron-right"
disabled={imageRegistryLoading}
/>
</Layout.Horizontal>
</Form>
</Layout.Vertical>
Expand Down
2 changes: 1 addition & 1 deletion translations/README-ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ChaosExperiment CR은 <a href="https://hub.litmuschaos.io" target="_blank">hub.l

(카오스 엔지니어링 사례로 Litmus를 사용하고 있는 조직은 위 페이지로 PR을 보내주세요)

## 라이센스
## 라이선스

Litmus는 아파치(Apache) 라이선스 버전 2.0을 적용합니다. 전체 라이선스 텍스트는 [LICENSE](./LICENSE)를 참고하세요. Litmus 프로젝트에서 사용하는 일부 프로젝트는 다른 라이선스에 적용받을 수 있으며, 별도의 라이선스를 참고하세요.

Expand Down

0 comments on commit 933a71f

Please sign in to comment.