Skip to content

Conversation

@n0rq1
Copy link
Contributor

@n0rq1 n0rq1 commented Nov 5, 2025

The second exercise provides a Dockerfile + code for a simple web app, the rest of the implementation is up to the user.

As opposed to what I originally had (Helm chart and some k8s manifests provided).

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (6)
  • examples/ch9/statefulsets/counterapp/server.js (39-41) Similar to the previous comment, errors in `writeCounter()` should be logged:
      } catch (e) {
        console.error('Error writing counter:', e);
        return false;
      }
    
  • examples/ch9/statefulsets/counterapp/server.js (18-33) The application uses synchronous file operations (`fs.existsSync`, `fs.mkdirSync`, `fs.writeFileSync`, `fs.readFileSync`) which can block the Node.js event loop. For a production application, consider using the asynchronous versions of these functions to improve performance under load.
  • examples/ch9/statefulsets/counterapp/server.js (27-29) The `JSON.parse()` call could throw an exception if the file contains invalid JSON, but it's not specifically handled. Consider adding a try-catch specifically for the parsing operation:
        const raw = fs.readFileSync(DATA_FILE, 'utf8');
        try {
          const obj = JSON.parse(raw);
          return typeof obj.count === 'number' ? obj.count : 0;
        } catch (parseError) {
          console.error('Error parsing counter file:', parseError);
          return 0;
        }
    
  • examples/ch9/statefulsets/counterapp/src/app.js (1-7) The fetchState function should provide error feedback to the user when the API call fails. Consider adding error handling to display a message when the API is unavailable.
    async function fetchState() {
      try {
        const res = await fetch('/api/state');
        if (!res.ok) {
          document.getElementById('count').textContent = 'Error';
          document.getElementById('podName').textContent = 'API unavailable';
          return;
        }
        const data = await res.json();
        document.getElementById('count').textContent = data.count;
        document.getElementById('podName').textContent = `pod: ${data.podName}`;
      } catch (error) {
        document.getElementById('count').textContent = 'Error';
        document.getElementById('podName').textContent = 'API unavailable';
        console.error('Failed to fetch state:', error);
      }
    }
    
  • examples/ch9/statefulsets/counterapp/src/app.js (9-14) The increment function should provide error feedback when the API call fails. Consider adding error handling similar to fetchState.
    async function increment() {
      try {
        const res = await fetch('/api/increment', { method: 'POST' });
        if (!res.ok) {
          document.getElementById('count').textContent = 'Error';
          return;
        }
        const data = await res.json();
        document.getElementById('count').textContent = data.count;
      } catch (error) {
        document.getElementById('count').textContent = 'Error';
        console.error('Failed to increment count:', error);
      }
    }
    
  • examples/ch9/statefulsets/counterapp/src/app.js (16-19) Consider adding a periodic refresh to automatically update the counter state. This would be particularly useful in a StatefulSet demonstration to show real-time updates from other pods.
    window.addEventListener('DOMContentLoaded', () => {
      document.getElementById('incrementBtn').addEventListener('click', increment);
      fetchState();
      
      // Refresh state every 5 seconds
      setInterval(fetchState, 5000);
    });
    

💡 To request another review, post a new comment with "/windsurf-review".

@jburns24
Copy link
Collaborator

jburns24 commented Dec 4, 2025

@n0rq1 Thank you for the section I am going to merge it. I did make some changes after going through the exercise but I would like to call out that you did have failing CI on this pr. there was markdown linting violations and missing front-matter. Make sure you are running npm install locally so you get the pre-commit hooks with husky that way you catch these things before CI

@jburns24 jburns24 merged commit 9b5c36f into master Dec 4, 2025
2 checks passed
@jburns24 jburns24 deleted the update-statefulsets branch December 4, 2025 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants